感觉区间合并都一个样,没什么好说的。
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define pb(a) push_back(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #else freopen("d:\in.txt","r",stdin); freopen("d:\out1.txt","w",stdout); #endif } int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!=' ')return ch; } return EOF; } const int MAXN=100100; struct node { int maxx,pre,suf,lv,rv,len; }; node tree[MAXN<<2]; void Merge(node &fa,node &l,node &r) { fa.len=l.len+r.len; fa.maxx=max(l.maxx,r.maxx,r.lv>l.rv?l.suf+r.pre:-1); fa.lv=l.lv;fa.rv=r.rv; fa.pre=l.pre==l.len&&l.rv<r.lv?l.pre+r.pre:l.pre; fa.suf=r.suf==r.len&&l.rv<r.lv?r.suf+l.suf:r.suf; } int build(int idx,int l,int r) { if(l==r) { int v; scanf("%d",&v); node &x=tree[idx]; x.len=x.pre=x.suf=x.maxx=1; x.lv=x.rv=v; return 0; } int mid=(r+l)>>1; build(lson); build(rson); Merge(tree[idx],tree[idx<<1],tree[idx<<1|1]); return 0; } int update(int idx,int l,int r,int x,int v) { if(l==r) { tree[idx].lv=tree[idx].rv=v; return 0; } int mid=(r+l)>>1; if(x<=mid)update(lson,x,v); else update(rson,x,v); Merge(tree[idx],tree[idx<<1],tree[idx<<1|1]); return 0; } node query(int idx,int l,int r,int tl,int tr) { if(tl<=l&&tr>=r) return tree[idx]; int mid=(r+l)>>1; if(tl<=mid&&tr>mid) { node q,a,b; a=query(lson,tl,tr); b=query(rson,tl,tr); Merge(q,a,b); return q; }else if(tl<=mid) return query(lson,tl,tr); else return query(rson,tl,tr); } int main() { int t; scanf("%d",&t); for(int ca=1;ca<=t;ca++) { int n,m; scanf("%d%d",&n,&m); build(1,0,n-1); for(int i=1;i<=m;i++) { char op=getch(); if(op=='Q') { int a,b; scanf("%d%d",&a,&b); node q=query(1,0,n-1,a,b); printf("%d ",q.maxx); }else { int x,v; scanf("%d%d",&x,&v); update(1,0,n-1,x,v); } } } return 0; }