TruE_Elysia @ 2024-07-21 11:23:17
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 10000005;
ll ans;
ll n, q, k;
ll a[MAXN];
ll tree[4 * MAXN];
ll lz[4 * MAXN];
bool cover[4 * MAXN];
void pushdown(int p, int s, int t) {
if (cover[p]) {
int mid = (s + t) / 2;
tree[2 * p] = tree[p];
tree[2 * p + 1] = tree[p];
lz[2 * p] = 0;
lz[2 * p + 1] = 0;
cover[2 * p] = true;
cover[2 * p + 1] = true;
cover[p] = false;
}
if (lz[p] != 0) {
int mid = (s + t) / 2;
tree[2 * p] += lz[p];
tree[2 * p + 1] += lz[p];
lz[2 * p] += lz[p];
lz[2 * p + 1] += lz[p];
lz[p] = 0;
}
}
void build(int s, int t, int p) {
if (s == t) {
tree[p] = a[s];
return;
}
int mid = (s + t) / 2;
build(s, mid, 2 * p);
build(mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void change(int l, int r, ll x, int s, int t, int p) {
if (l <= s && r >= t) {
tree[p] = x;
lz[p] = 0;
cover[p] = true;
return;
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) change(l, r, x, s, mid, 2 * p);
if (r > mid) change(l, r, x, mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll k, int s, int t, int p) {
if (l <= s && r >= t) {
tree[p] += k;
lz[p] += k;
return;
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) update(l, r, k, s, mid, 2 * p);
if (r > mid) update(l, r, k, mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
ll query(int l, int r, int s, int t, int p) {
if (l <= s && r >= t) {
return tree[p];
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) ans = max(ans, query(l, r, s, mid, 2 * p));
if (r > mid) ans = max(ans, query(l, r, mid + 1, t, 2 * p + 1));
return ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("P1253_6.in","r",stdin);
// freopen("cesh.txt","w",stdout);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,n,1);
for(int i=1;i<=q;i++){
int op=0;
cin>>op;
if(op==1){
int l,r,x=0;
cin>>l>>r>>x;
change(l,r,x,1,n,1);
}
if(op==2){
int l,r;
cin>>l>>r>>k;
update(l,r,k,1,n,1);
}
if(op==3){
int l,r=0;
cin>>l>>r;
ans = LLONG_MIN;
ans=query(l,r,1,n,1);
cout<<ans<<endl;
}
}
return 0;
}
by TruE_Elysia @ 2024-07-21 11:24:48
记录在这里
60分记录
by cxjy @ 2024-07-27 08:29:47
原因就是懒标记的先后顺序没处理好,你就考虑两种情况,如果一段区间本身存在lz标记,然后你给它打上cover标记的时候,你要把它的lz标记清零!!如果这一段区间原本存在cover标记,你再给他打赏lz标记的时候,要先把它的cover标记下移。
by TruE_Elysia @ 2024-07-29 20:30:48
@cxjy 谢谢,关注了
by f3173155796 @ 2024-07-31 00:56:16
@TruE_Elysia 所以咋修改,我跟你写的代码基本上一样,我没看出来啥错误啊