【HDU】3308 LCIS
2012-05-24 15:50
176 查看
#include<cstdio> #define MAXN 100010 struct node { int left,right,val; }; int a[MAXN]; node tree[MAXN<<2]; inline int MAX(int x,int y) { return x>y?x:y; } inline int MIN(int x,int y) { return x>y?y:x; } inline void PushUp(int mid,int L,int R,int rt) { tree[rt].left=tree[rt<<1].left; tree[rt].right=tree[rt<<1|1].right; tree[rt].val=MAX(tree[rt<<1].val,tree[rt<<1|1].val); if(a[mid]<a[mid+1]) { if(tree[rt].left==mid-L+1) tree[rt].left+=tree[rt<<1|1].left; if(tree[rt].right==R-mid) tree[rt].right+=tree[rt<<1].right; tree[rt].val=MAX(tree[rt].val,tree[rt<<1].right+tree[rt<<1|1].left); } } void Build(int L,int R,int rt) { if(L==R) { scanf("%d",&a[L]); tree[rt].left=tree[rt].val=tree[rt].right=1; } else { int mid=(L+R)>>1; Build(L,mid,rt<<1); Build(mid+1,R,rt<<1|1); PushUp(mid,L,R,rt); } } void Update(int x,int val,int L,int R,int rt) { if(L==R) a[L]=val; else { int mid=(L+R)>>1; if(mid>=x) Update(x,val,L,mid,rt<<1); else Update(x,val,mid+1,R,rt<<1|1); PushUp(mid,L,R,rt); } } int Query(int x,int y,int L,int R,int rt) { if(x<=L&&R<=y) return tree[rt].val; int mid=(L+R)>>1,ans=0; if(mid>=x) ans=MAX(ans,Query(x,y,L,mid,rt<<1)); if(y>mid) ans=MAX(ans,Query(x,y,mid+1,R,rt<<1|1)); if(a[mid]<a[mid+1]) ans=MAX(ans,MIN(mid-x+1,tree[rt<<1].right)+MIN(y-mid,tree[rt<<1|1].left)); return ans; } int main() { char ch; int c,n,m,x,y; scanf("%d",&c); while(c--) { scanf("%d%d",&n,&m); Build(1,n,1); while(m--) { scanf(" %c%d%d",&ch,&x,&y); if(ch=='U') Update(x+1,y,1,n,1); else printf("%d\n",Query(x+1,y+1,1,n,1)); } } return 0; }
相关文章推荐
- HDU-3308 LCIS 线段树 区间处理
- HDU - 3308 LCIS(线段树)
- HDU - 3308 LCIS (线段树 单点更新 区间查询)
- hdu 3308 LCIS
- HDU 3308 LCIS(线段树)
- hdu 3308 LCIS (线段树+单点更新+区间合并)
- HDU 3308 LCIS
- hdu--3308 LCIS(线段树+区间合并)
- HDU 3308 LCIS (端点更新+区间合并)
- hdu 3308 LCIS(线段树 最长连续递增)
- HDU 3308 LCIS
- HDU 3308 LCIS 线段树区间更新
- HDU 3308 - LCIS(线段树+区间合并)
- HDU 3308 LCIS
- hdu 3308 LCIS
- HDU 3308 LCIS (线段树~)
- hdu 3308 线段树区间 LCIS
- HDU 3308 LCIS(线段树单点更新区间合并)
- HDU 3308 LCIS(线段树区间合并)
- HDU 3308 LCIS(线段树:单点更新,求最大连续子串)