Dream_World @ 2022-07-10 11:55:33
蒟蒻不会线段树,用的数组解,只有五十分(后面4WA,1TLE),求大佬帮我看看
#include<bits/stdc++.h>
using namespace std;
int n, q, op, l, r, x, a[1000005], maxn = -1;
int main(){
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 0; i < q; i++){
scanf("%d", &op);
if(op == 1){
scanf("%d%d%d", &l, &r, &x);
for(int j = l; j <= r; j++) a[j] = x;
}
else if(op == 2){
scanf("%d%d%d", &l, &r, &x);
for(int j = l; j <= r; j++) a[j] += x;
}
else if(op == 3){
scanf("%d%d", &l, &r);
maxn = -1;
for(int j = l; j <= r; j++) maxn = max(maxn, a[j]);
printf("%d\n", maxn);
}
}
return 0;
}
by worldking @ 2022-07-10 22:23:21
开long long 试试
by anonymous_letter @ 2022-07-12 18:38:19
。。。这样肯定会超时啊,得使用