HDU 3308 LCIS
2014-07-07 00:25
141 查看
LCIS
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3810 Accepted Submission(s): 1724
Problem Description
Given n integers.
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
Input
T in the first line, indicating the case number.
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
Output
For each Q, output the answer.
Sample Input
1 10 10 7 7 3 3 5 9 9 8 1 8 Q 6 6 U 3 4 Q 0 1 Q 0 5 Q 4 7 Q 3 5 Q 0 2 Q 4 6 U 6 10 Q 0 9
Sample Output
1 1 4 2 3 1 2 5
Author
shǎ崽
Source
HDOJ Monthly Contest – 2010.02.06
解题思路:线段树单点修改区间合并
#include <iostream> #include <cstdio> #include <cstring> #define Maxn 100005 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; struct { int lnum; int rnum; int lsum; int rsum; int msum; }tree[Maxn<<2]; void push_up(int rt,int d) { tree[rt].lnum=tree[rt<<1].lnum; tree[rt].rnum=tree[rt<<1|1].rnum; tree[rt].lsum=tree[rt<<1].lsum; tree[rt].rsum=tree[rt<<1|1].rsum; if(tree[rt<<1].rnum<tree[rt<<1|1].lnum&&tree[rt].lsum==d-(d>>1)) tree[rt].lsum+=tree[rt<<1|1].lsum; if(tree[rt<<1].rnum<tree[rt<<1|1].lnum&&tree[rt].rsum==(d>>1)) tree[rt].rsum+=tree[rt<<1].rsum; if(tree[rt<<1].rnum<tree[rt<<1|1].lnum) tree[rt].msum=max(tree[rt<<1].rsum+tree[rt<<1|1].lsum,max(tree[rt<<1].msum,tree[rt<<1|1].msum)); else tree[rt].msum=max(tree[rt<<1].msum,tree[rt<<1|1].msum); } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&tree[rt].lnum); tree[rt].rnum=tree[rt].lnum; tree[rt].lsum=tree[rt].rsum=tree[rt].msum=1; return ; } int m=(l+r)>>1; build(lson); build(rson); push_up(rt,r-l+1); } void update(int pos,int x,int l,int r,int rt) { if(l==r) { tree[rt].lnum=tree[rt].rnum=x; return ; } int m=(l+r)>>1; if(pos<=m) update(pos,x,lson); else update(pos,x,rson); push_up(rt,r-l+1); } int query(int L,int R,int l,int r,int rt) { int ans=0; if(L<=l&&R>=r) return ans=tree[rt].msum; int m=(l+r)>>1; if(L<=m) ans=max(ans,query(L,R,lson)); if(R>m) ans=max(ans,query(L,R,rson)); if(tree[rt<<1].rnum<tree[rt<<1|1].lnum&&L<=m&&R>m) ans=max(ans,min(R,m+tree[rt<<1|1].lsum)-max(L,m-tree[rt<<1].rsum+1)+1); return ans; } int main() { int t,n,m,a,b; char str[3]; freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); build(1,n,1); while(m--) { scanf("%s%d%d",str,&a,&b); if(str[0]=='Q') printf("%d\n",query(a+1,b+1,1,n,1)); else update(a+1,b,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 线段树维护区间lcs
- Hdu 3308 LCIS
- HDU 3308 LCIS(线段树)
- HDU 3308 LCIS (线段树合并区间)