_Coffice_ @ 2023-04-30 07:33:22
#include<iostream>
using namespace std;
struct Tree
{
long long l,r;
long long d;
long long tag1, // 区间赋值
tag2; // 区间加
bool flag1,flag2;
};
Tree t[4000005];
long long a[1000005];
long long lc(long long p)
{
return p*2;
}
long long rc(long long p)
{
return p*2+1;
}
long long mid(long long l,long long r)
{
return (l+r)/2;
}
void js(long long p,long long l,long long r)
{
t[p].l = l;
t[p].r = r;
t[p].tag1 = 0;
t[p].tag2 = 0;
t[p].flag1 = 0;
t[p].flag2 = 0;
if(l == r)
{
t[p].d = a[l];
return ;
}
long long m = mid(l,r);
js(lc(p),l,m);
js(rc(p),m+1,r);
t[p].d = max(t[lc(p)].d,t[rc(p)].d);
return ;
}
void f1(long long p,long long t1)
{
t[p].tag1 = t1;
t[p].flag1 = 1;
t[p].d = t1;
return ;
}
void f2(long long p,long long t2)
{
t[p].tag2 += t2;
t[p].flag2 = 1;
t[p].d += t2;
return ;
}
void down(long long p)
{
if(t[p].flag1 != 0)
{
f1(lc(p),t[p].tag1);
f1(rc(p),t[p].tag1);
t[p].flag1 = 0;
t[p].tag1 = 0;
}
if(t[p].flag2 != 0)
{
f2(lc(p),t[p].tag2);
f2(rc(p),t[p].tag2);
t[p].flag2 = 0;
t[p].tag2 = 0;
}
t[p].d = max(t[lc(p)].d,t[rc(p)].d);
return ;
}
void upd(long long p,long long l,long long r,long long x) // 区间赋值
{
if(l <= t[p].l && r >= t[p].r)
{
t[p].d = x;
t[p].tag1 = x;
t[p].flag1 = 1;
return ;
}
down(p);
long long m = mid(t[p].l,t[p].r);
if(l <= m)
{
upd(lc(p),l,r,x);
}
if(r >= m+1)
{
upd(rc(p),l,r,x);
}
t[p].d = max(t[lc(p)].d,t[rc(p)].d);
return ;
}
void add(long long p,long long l,long long r,long long x) // 区间加
{
if(l <= t[p].l && r >= t[p].r)
{
t[p].d += x;
t[p].flag2 = 1;
t[p].tag2 += x;
return ;
}
down(p);
long long m = mid(t[p].l,t[p].r);
if(l <= m)
{
add(lc(p),l,r,x);
}
if(r >= m+1)
{
add(rc(p),l,r,x);
}
t[p].d = max(t[lc(p)].d,t[rc(p)].d);
return ;
}
long long max_(long long p,long long l,long long r) // 区间最值
{
if(l <= t[p].l && r >= t[p].r)
{
return t[p].d;
}
down(p);
long long m = mid(t[p].l,t[p].r);
long long ans = -1000000000002;
if(l <= m)
{
ans = max(ans,max_(lc(p),l,r));
}
if(r >= m+1)
{
ans = max(ans,max_(rc(p),l,r));
}
return ans;
}
int main()
{
long long n,q;
scanf("%lld%lld",&n,&q);
for(long long i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
js(1,1,n);
for(long long i=1;i<=q;i++)
{
long long op;
scanf("%lld",&op);
if(op == 1)
{
long long l,r,x;
scanf("%lld%lld%lld",&l,&r,&x);
upd(1,l,r,x);
}
else if(op == 2)
{
long long l,r,x;
scanf("%lld%lld%lld",&l,&r,&x);
add(1,l,r,x);
}
else
{
long long l,r;
scanf("%lld%lld",&l,&r);
printf("%lld\n",max_(1,l,r));
}
}
return 0;
}
WA 6-10
by xzCyanBrad @ 2023-04-30 07:55:59
void f1(long long p,long long t1)
{
t[p].tag1 = t1;
t[p].flag1 = 1;
t[p].d = t1;
t[p].tag2 = 0;
t[p].flag2 = 0; // 加上这两行,(要清空加的标记)
return ;
}
by xzCyanBrad @ 2023-04-30 07:59:17
@czw20110831
by _Coffice_ @ 2023-04-30 08:01:42
好的,我试试,谢谢大佬
by _Coffice_ @ 2023-04-30 08:05:43
还是60,求大佬好人做到底,已关注,蒟蒻在此%%%
by _Coffice_ @ 2023-04-30 08:06:50
@LKX_Wata
by _Coffice_ @ 2023-04-30 08:34:49
大佬呢??继续悬赏关注,求调!!!
有大佬吗???
橙名蒟蒻在此 %%%
by _Coffice_ @ 2023-04-30 08:43:56
@LKX_Wata
by _Coffice_ @ 2023-04-30 08:45:52
人呢,急!
by _Coffice_ @ 2023-04-30 08:53:17
by _Coffice_ @ 2023-04-30 09:24:13
@LKX_Wata
@LKX_Wata
@LKX_Wata
@LKX_Wata
@LKX_Wata