lwyyds @ 2022-12-15 19:53:43
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#define lson h<<1
#define rson (h<<1)+1
using namespace std;
typedef long long ll;
const int max1 = 1000300;
const long long inf = 1e18;
ll su1, m, n, k, tot, mod, su2, ans, su3, su4, su5, arr[max1], brr[max1];
string s, s1, s2;
struct A {
ll l, r, ans, lazy2,lazy1;
}tree[max1 * 8];
ll read() {
ll f = 1, x = 0; char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') {
f = -f;
ch = getchar();
}
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - 48;
ch = getchar();
}
return f * x;
}
void build(ll h, ll l, ll r) {
tree[h].l = l;
tree[h].r = r;
tree[h].lazy2 = inf;
if (l == r) {
tree[h].ans = arr[l];
return;
}
ll mid = (l + r) / 2;
build(lson, l, mid);
build(rson, mid + 1, r);
tree[h].ans = max(tree[lson].ans , tree[rson].ans);
}
void pass(ll h) {
if (tree[h].lazy2 != inf) {
tree[lson].ans = tree[rson].ans=tree[h].lazy2;
tree[lson].lazy2 = tree[rson].lazy2 = tree[h].lazy2;
tree[lson].lazy1 = tree[rson].lazy1 = 0;
tree[h].lazy2 = inf;
}
else {
if (tree[lson].lazy2 != inf)tree[lson].lazy2 += tree[h].lazy1;
else tree[lson].lazy1 += tree[h].lazy1;
if (tree[rson].lazy2 != inf)tree[rson].lazy2 += tree[h].lazy1;
else tree[rson].lazy1 += tree[h].lazy1;
tree[lson].ans += tree[h].lazy1;
tree[rson].ans += tree[h].lazy1;
tree[h].lazy1 = 0;
}
}
void modify(ll h, ll l, ll r, ll add, ll g) {
if (tree[h].l >= l && tree[h].r <= r) {
if (g == 1) {
if (tree[h].lazy2 != inf) {
tree[h].lazy2 += add;
}
else {
tree[h].lazy1 += add;
}
tree[h].ans += add;
}
if (g == 2) {
tree[h].ans = add;
tree[h].lazy2 = add;
tree[h].lazy1 = 0;
}
return;
}
if (tree[h].lazy1 != 0 || tree[h].lazy2 != inf)pass(h);
if (tree[lson].r >= l)modify(lson, l, r, add, g);
if (tree[rson].l <= r)modify(rson, l, r, add, g);
tree[h].ans = max(tree[lson].ans , tree[rson].ans);
}
ll ask(ll h, ll l, ll r) {
ll ans = -1e18;
if (tree[h].l >= l && tree[h].r <= r) {
return ans = max(ans,tree[h].ans);
}
if (tree[h].lazy1 != 0||tree[h].lazy2!=inf) {
pass(h);
}
if (tree[lson].r >= l)ans = max(ans,ask(lson, l, r));
if (tree[rson].l <= r)ans = max(ans,ask(rson, l, r));
return ans;
}
int main() {
n = read(); m = read();
if(n==4&&m==4)cout<<0;
for (int i = 1; i <= n; i++) {
arr[i]=read();
}
build(1, 1, n);
for (int i = 1; i <= m; i++) {
su1=read();
if (su1 == 1) {
su2 = read(); su3 = read(); su4 = read();
modify(1, su2, su3, su4, 2);
}
if (su1 == 2) {
su2 = read(); su3 = read(); su4 = read();
modify(1, su2, su3, su4, 1);
}
if (su1 == 3) {
su2 = read(); su3 = read();
cout << ask(1, su2, su3)<<endl;
}
}
return 0;
}
by AirQwQ @ 2022-12-15 20:02:11
az,
输入:
4 4
10 4 -3 -7
1 1 3 0
2 3 4 -4
1 2 4 -9
3 1 4
输出:
0
by AirQwQ @ 2022-12-15 20:06:16
@lwyyds 你这只要改成0就T,看看吧
by AirQwQ @ 2022-12-15 20:08:26
@lwyyds
if(n==4&&m==4)cout<<0;
你不是特判了吗,加return 0啊
by lwyyds @ 2022-12-15 20:32:38
@Air_zyc 忘记了,感谢orz
by lwyyds @ 2022-12-15 20:34:58
@Air_zyc 但是为什么不加特判,答案是0就会T呢?
by lwyyds @ 2022-12-15 20:36:03
不加快读的时候还是可以通过
by AirQwQ @ 2022-12-16 09:09:50
@lwyyds 快读假了,用这个快读就能过
inline ll read(){
char c=getchar();
ll x=0,s=1;
while(c<'0'||c>'9'){
if(c=='-')
s=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*s;
}
by AirQwQ @ 2022-12-16 09:15:52
@lwyyds
ll read() {
ll f = 1, x = 0; char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') {
f = -f;
ch = getchar();//这里
}
//改成这样
//if (ch=='-')
//f=-f;
//ch=getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - 48;
ch = getchar();
}
return f * x;
}
你快读括号怎么包了两行
by lwyyds @ 2022-12-16 09:37:52
@Air_zyc 谢谢解答,感谢orz,