标签:
Time Limit: 6000/2000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5591 Accepted Submission(s): 2443
///1085422276 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<bitset> #include<set> #include<vector> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)) #define memfy(a) memset(a,-1,sizeof(a)) #define TS printf("111111\n"); #define FOR(i,a,b) for( int i=a;i<=b;i++) #define FORJ(i,a,b) for(int i=a;i>=b;i--) #define READ(a,b) scanf("%d%d",&a,&b) #define mod 1000000007 #define inf 1000000001 #define maxn 200000+2 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } //**************************************** struct ss { int l,r,v,ans; int lc,rc; }tr[maxn<<2]; int a[maxn<<2],n,q; void push_up(int k) { if(a[tr[k<<1].r]<a[tr[k<<1|1].l]) { tr[k].ans=max(max(tr[k<<1].ans,tr[k<<1|1].ans),tr[k<<1].rc+tr[k<<1|1].lc); if(tr[k<<1].lc==(tr[k<<1].r-tr[k<<1].l+1)) { tr[k].lc=tr[k<<1].lc+tr[k<<1|1].lc; }else tr[k].lc=tr[k<<1].lc; if(tr[k<<1|1].lc==(tr[k<<1|1].r-tr[k<<1|1].l+1)) { tr[k].rc=tr[k<<1|1].rc+tr[k<<1].rc; }else tr[k].rc=tr[k<<1|1].rc; } else { tr[k].ans=max(tr[k<<1].ans,tr[k<<1|1].ans); tr[k].lc=tr[k<<1].lc; tr[k].rc=tr[k<<1|1].rc; } } void build(int k,int s,int t) { tr[k].l=s; tr[k].r=t; if(s==t) { tr[k].v=a[s]; tr[k].ans=1; tr[k].lc=1; tr[k].rc=1; return ; } int mid=(s+t)>>1; build(k<<1,s,mid); build(k<<1|1,mid+1,t); push_up(k); } void update(int k,int x,int c) { if(tr[k].l==x&&tr[k].r==x) { tr[k].v=c; a[x]=c; return ; } int mid=(tr[k].l+tr[k].r)>>1; if(x<=mid)update(k<<1,x,c); else update(k<<1|1,x,c); push_up(k); } int ask(int k,int s,int t) { if(tr[k].l==s&&tr[k].r==t) { return tr[k].ans; } int mid=(tr[k].l+tr[k].r)>>1; if(t<=mid)return ask(k<<1,s,t); else if(s>mid)return ask(k<<1|1,s,t); else { int ret=0; int A=ask(k<<1,s,mid); int B=ask(k<<1|1,mid+1,t); ret=max(A,B); A=min(tr[k<<1].rc,mid-s+1); B=min(tr[k<<1|1].lc,t-mid); if(a[tr[k<<1].r]<a[tr[k<<1|1].l]) ret=max(A+B,ret); return ret; } } int main() { int T=read(); while(T--) { n=read(); q=read(); FOR(i,1,n) { a[i]=read(); } build(1,1,n); int a,b; char ch[321]; FOR(i,1,q) { scanf("%s%d%d",ch,&a,&b); if(ch[0]==‘Q‘) { printf("%d\n",ask(1,a+1,b+1)); } else update(1,a+1,b); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4790424.html