Coding_Zhouzehao @ 2022-09-08 16:34:15
#include<iostream>
#define ll long long
#define lc p << 1
#define rc p << 1 | 1
#define mid ((l + r) >> 1)
using namespace std;
const int MAXN = 1e5 + 5;
const ll inf = 1e18;
struct tree
{
ll tag1,tag2;
//tag1表示区间赋值为tag1
//tag2表示区间加上tag2
ll Max;
int l,r;
bool used;
} t[MAXN << 2];
int n, m;
ll a[MAXN];
void push_up(int p)
{
t[p].Max = max(t[lc].Max,t[rc].Max);
}
void push_down(int p)
{
if(t[p].used)//是否有tag1
{
t[lc].tag1 = t[rc].tag1 = t[p].tag1;
t[lc].tag2 = t[rc].tag2 = t[p].tag2;
t[lc].Max = t[rc].Max = t[p].tag1 + t[p].tag2;
t[lc].used = t[rc].used = 1;
}
else
{
t[lc].tag2 += t[p].tag2,t[rc].tag2 += t[p].tag2;
t[lc].Max += t[p].tag2,t[rc].Max += t[p].tag2;
}
t[p].used = 0;
t[p].tag1 = t[p].tag2 = 0;
}
void biuld(int p,int l,int r)
{
t[p].l = l,t[p].r = r,t[p].Max = -inf;
if(l == r)
{
t[p].Max = a[l];
return;
}
biuld(lc,l,mid);biuld(rc,mid+1,r);
push_up(p);
}
void change(int p,int l,int r,ll x)
{
if(l <= t[p].l && t[p].r <= r)//完全被包含
{
t[p].tag1 = x,t[p].tag2 = 0;
t[p].Max = x,t[p].used = 1;
return;
}
if(l <= mid) change(lc,l,r,x);
if(mid + 1 <= r)change(rc,l,r,x);
push_up(p);
}
void add(int p,int l,int r,ll x)
{
if(l <= t[p].l && t[p].r <= r)
{
t[p].tag2 += x,t[p].Max += x;
return;
}
push_down(p);//标记下传
if(l <= mid)add(lc,l,r,x);
if(mid + 1 <= r)add(rc,l,r,x);
push_up(p);
}
ll query(int p,int l,int r)
{
if(l <= t[p].l && r <= t[p].r)
return t[p].Max;
push_down(p);
ll ans = -inf;
if(l <= mid) ans = max(ans,query(lc,l,r));
if(mid + 1 <= r)ans = max(ans,query(rc,l,r));
return ans;
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",a+i);
biuld(1,1,n);
for(int i=1;i<=m;i++)
{
int op,l,r;
ll x;
scanf("%d%d%d",&op,&l,&r);
if(op == 1 || op == 2)
scanf("%lld",&x);
if(op == 1)
change(1,l,r,x);
else if(op == 2)
add(1,l,r,x);
else
printf("%lld\n",query(1,l,r));
}
}
by bamboo12345 @ 2022-09-08 16:39:30
@Coding_zhouzehao 十分标准的把build全部拼错了(doge)
by bamboo12345 @ 2022-09-08 16:42:25
@Coding_zhouzehao change和add让你RE的
by Coding_Zhouzehao @ 2022-09-08 16:43:27
@bamboo123 az,谢谢大佬
by Coding_Zhouzehao @ 2022-09-08 17:26:51
define 的 mid 用的太狂妄了@bamboo123 ,改了后就50pts了
by Coding_Zhouzehao @ 2022-09-08 17:27:44
还有query里的边界判断