_joker_r @ 2024-08-16 11:34:20
我照着题解改了,但是20pts AC on #1,#3
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,q,a[1000010];
#define none -0x3f3f3f3f
int lr(int x){return x<<1;}
int rr(int x){return x<<1|1;}
struct tree
{
int maxn,cover,add;
}t[4000010];
void push_up(int p)
{
t[p].maxn=max(t[lr(p)].maxn,t[rr(p)].maxn);
}
void cover_down(int p)
{
if(t[p].cover!=none)
{
t[lr(p)].add=0;
t[rr(p)].add=0;
t[lr(p)].maxn=t[p].cover;
t[rr(p)].maxn=t[p].cover;
t[lr(p)].cover=t[p].cover;
t[rr(p)].cover=t[p].cover;
t[p].cover=none;
}
}
void add_down(int p)
{
t[lr(p)].add+=t[p].add;
t[rr(p)].add+=t[p].add;
t[lr(p)].maxn+=t[p].add;
t[rr(p)].maxn+=t[p].add;
t[p].add=0;
}
void push_down(int p)
{
cover_down(p);
add_down(p);
}
void build(int p,int x,int y)
{
t[p].cover=none;
if(x==y)
{
t[p].maxn=a[x];
return;
}
int m=x+y>>1;
build(lr(p),x,m),build(rr(p),m+1,y);
push_up(p);
}
void do_cover(int p,int k,int l,int r,int x,int y)
{
if(x<=l and r<=y)
{
t[p].cover=k;
t[p].add=0;
t[p].maxn=k;
return;
}
push_down(p);
int m=l+r>>1;
if(x<=m)do_cover(lr(p),k,l,m,x,y);
if(y>m)do_cover(rr(p),k,m+1,r,x,y);
push_up(p);
}
void do_add(int p,int k,int l,int r,int x,int y)
{
if(x<=l and r<=y)
{
t[p].add+=k;
t[p].maxn+=k;
return;
}
push_down(p);
int m=l+r>>1;
if(x<=m)do_add(lr(p),k,l,m,x,y);
if(y>m)do_add(rr(p),k,m+1,r,x,y);
push_up(p);
}
int maxx(int p,int l,int r,int x,int y)
{
if(x<=l and r<=y)
{
return t[p].maxn;
}
push_down(p);
int m=l+r>>1,ma=-0x3f3f3f3f;
if(x<=m)ma=max(ma,maxx(p,l,m,x,y));
if(y>m)ma=max(ma,maxx(p,m+1,r,x,y));
return ma;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(q--)
{
int o,x,y,k;
cin>>o>>x>>y;
if(o==1)
{
cin>>k;
do_cover(1,k,1,n,x,y);
}
if(o==2)
{
cin>>k;
do_add(1,k,1,n,x,y);
}
if(o==3)
{
cout<<maxx(1,1,n,x,y)<<'\n';
}
}
}
by _joker_r @ 2024-08-17 17:10:34
我真是,maxx函数递归直接写的p,没写lr(p)和rr(p),none和ma还开小了
by _joker_r @ 2024-08-17 17:10:53
已AC,此帖结