HDU 3308 LCIS

来源:互联网 发布:淘宝到货短信提醒 编辑:程序博客网 时间:2024/05/17 02:47

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
110 107 7 3 3 5 9 9 8 1 8 Q 6 6U 3 4Q 0 1Q 0 5Q 4 7Q 3 5Q 0 2Q 4 6U 6 10Q 0 9
 

Sample Output
11423125
 

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|1using 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));elsetree[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);elseupdate(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));elseupdate(a+1,b,1,n,1);}}return 0;}


 
0 0