这是什么语言,为啥不用定义类型qwq
by Buried_Dream @ 2023-11-16 06:22:00
@[cz_awa](/user/246331) 同问
by Twiter_ln @ 2023-11-16 07:44:20
同问
by Ryan_jiang07 @ 2023-11-16 07:59:45
@[cz_awa](/user/246331) 有你这么建树的吗(还边读入边建)……
by 5t0_0r2 @ 2023-11-16 08:35:15
@[Buried_Dream](/user/396974) @[Twiter_ln](/user/188970) @[Ryan_jiang07](/user/401787) 这是C语言
@[5t0_0r2](/user/999274) 好,我改改
by cat_lover1 @ 2023-11-16 09:18:02
@[cz_awa](/user/246331) 还有你的 ``upd`` 传了 ``op`` 的参数吗
by 5t0_0r2 @ 2023-11-16 09:26:32
@[cz_awa](/user/246331) 还有你的 nul 小了(你加两次 10^9)不就超过了么
by 5t0_0r2 @ 2023-11-16 09:29:35
@[5t0_0r2](/user/999274) 为什么不能边读边建
by Buried_Dream @ 2023-11-16 09:30:51
@[Buried_Dream](/user/396974) 容易出 bug
by 5t0_0r2 @ 2023-11-16 09:31:32
@[cz_awa](/user/246331) 或者可参考这一份代码:
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 9,INF = 1e18,ROOT = 1;
int a[N];
struct seg_tree{
struct node {
int val,add,change;
} tree[N << 2];
bool in_range(int l,int r,int now_l,int now_r){
return l <= now_l && now_r <= r;
}
bool out_range(int l,int r,int now_l,int now_r){
return now_r < l || now_l > r;
}
void push_up(int root){
int lchild = root * 2,rchild = root * 2 + 1;
tree[root].val = max(tree[lchild].val,tree[rchild].val);
}
void make_tag(int root,int x,int type){
if(type == 1){
tree[root].add = 0;
tree[root].change = x;
tree[root].val = x;
}
else{
if(tree[root].change == INF)
tree[root].add += x;
else
tree[root].change += x;
tree[root].val += x;
}
}
void push_down(int root){
int lchild = root * 2,rchild = root * 2 + 1;
if(tree[root].change == INF){
make_tag(lchild,tree[root].add,2);
make_tag(rchild,tree[root].add,2);
tree[root].add = 0;
}
else{
make_tag(lchild,tree[root].change,1);
make_tag(rchild,tree[root].change,1);
tree[root].change = INF;
}
}
void build(int l,int r,int root) {
tree[root].change = INF;
if(l == r) {
tree[root].val = a[l];
return;
}
int mid = (l + r) / 2,lchild = root * 2,rchild = root * 2 + 1;
build(l,mid,lchild);
build(mid + 1,r,rchild);
push_up(root);
}
void update(int l,int r,int now_l,int now_r,int root,int c,int type) {
if(in_range(l,r,now_l,now_r)) {
make_tag(root,c,type);
return;
}
else if(!out_range(l,r,now_l,now_r)){
int mid = (now_l + now_r) / 2,lchild = root * 2,rchild = root * 2 + 1;
push_down(root);
update(l,r,mid + 1,now_r,rchild,c,type);
update(l,r,now_l,mid,lchild,c,type);
push_up(root);
}
return;
}
int getmax(int l, int r, int now_l, int now_r, int root) {
int mid = (now_l + now_r) / 2,lchild = root * 2,rchild = root * 2 + 1;
if(in_range(l,r,now_l,now_r))
return tree[root].val;
else if(!out_range(l,r,now_l,now_r)){
push_down(root);
return max(getmax(l,r,now_l,mid,lchild),getmax(l,r,mid + 1,now_r,rchild));
}
else
return -INF;
}
} seg;
int n,m;
int op,l,r,k;
signed main() {
scanf("%lld%lld", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
seg.build(1,n,ROOT);
for(int i = 1; i <= m; i++) {
scanf("%lld", &op);
if(op == 1 || op == 2){
scanf("%lld%lld%lld" ,&l, &r, &k);
seg.update(l,r,1,n,ROOT,k,op);
}
else{
scanf("%lld%lld", &l, &r);
printf("%lld\n",seg.getmax(l,r,1,n,1));
}
}
}
```
by 5t0_0r2 @ 2023-11-16 09:32:01