摆烂之在学校不好好上课
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
const int N=2e5+7,M=N*4;
int n,q;
int a[N],b[N];
struct Node
{
int l,r;
int pre,ll;//pre-->区间的第一个数 ll-->最长非递减前缀
int last,lr;//last-->区间最后一个数 lr-->最长非递减后缀
int ans;
void init(int _)
{
pre=last=_;
ans=ll=lr=1;
}
}tr[M];
void pushup(Node &t,Node &left,Node &right)
{
t.ans=left.ans+right.ans;
t.pre=left.pre,t.last=right.last;
t.ll=left.ll,t.lr=right.lr;
if(right.pre>=left.last)
{
int x=left.r-left.l+1;
int y=right.r-right.l+1;
t.ans+=right.ll*left.lr;
if(x==left.lr)t.ll=x+right.ll;
if(y==right.ll)t.lr=y+left.lr;
}
}
void pushup(int u)
{
pushup(tr[u],tr[u<<1],tr[u<<1|1]);
}
void build(int u,int l,int r)
{
tr[u].l=l,tr[u].r=r;
if(l==r)
{
tr[u].init(a[l]);
return;
}
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
void modify(int u,int x,int y)
{
if(tr[u].l==x&&tr[u].r==x)
{
tr[u].init(y);
}
else
{
int mid=tr[u].l+tr[u].r>>1;
if(x<=mid)modify(u<<1,x,y);
else modify(u<<1|1,x,y);
pushup(u);
}
}
Node query(int u,int l,int r)
{
if(tr[u].l>=l&&tr[u].r<=r)return tr[u];
else
{
int mid=tr[u].l+tr[u].r>>1;
if(r<=mid)return query(u<<1,l,r);
else if(l>mid)return query(u<<1|1,l,r);
else
{
Node left=query(u<<1,l,r);
Node right=query(u<<1|1,l,r);
Node res;
pushup(res,left,right);
return res;
}
}
}
signed main()
{
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
build(1,1,n);
while(q--)
{
int op,x,y;
scanf("%lld%lld%lld",&op,&x,&y);
if(op==1) modify(1,x,y);
else printf("%lld\n",query(1,x,y).ans);
}
return 0;
}
好强!
OvO
没有思路!!
差评😏
QWQ