LCIs
Time limit:6000/2000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6166 Accepted Submission (s): 2675
Problem descriptiongiven n integers.
You have both 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].
Inputt in the first line, indicating the case number.
Each case is starts with the integers n, m (0<n,m<=105).
The next line has n integers (0<=val<=105).
The next m lines each have an operation:
U A B (0<=a,n, 0<=b=105)
OR
Q A B (0<=a<=b< N).
Outputfor each Q, output the answer.
Sample Input110 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 Output11423125 The first interval of the segment tree to merge.
See the puzzle, from the afternoon to do the evening ... However, it is a simple interval merger ... Sang-xin ...
Gives a sequence that can be updated in a single point to find the longest continuous increment of the length of a child column.
Each section of the record
struct Node
{
int L,r,len; Left and right end points in a segment tree, and sequence length
int ln,rn; The sequence on this segment is the left and right end
int lm,rm,nm; Contains the left endpoint, which contains the right endpoint, and the longest increment continuous child column length of the whole segment
} tree[maxn<<2];
The length (nm) of the longest consecutive incrementing child column in a sequence (RT) is Max (TREE[RT<<1].NM,TREE[RT<<1|1].NM) and satisfies tree[rt<<1].rn<tree[rt <<1|1].LN (left child's right endpoint small less right operand child's left end) in the condition of the larger of the TREE[RT<<1].RM+TREE[RT<<1|1].LM. After the update point pushup and query are using this idea.
The first wave timeout is due to mid= (L+R)/2, using bit arithmetic faster, mid= (l+r) >>1
There was a problem with the query function writing before.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineMAXN 100005#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1structnode{intL,r,len; intLn,rn; intlm,rm,nm;} TREE[MAXN<<2];intnum[100005];voidPushup (intRT) {Tree[rt].ln=tree[rt<<1].ln; Tree[rt].rn=tree[rt<<1|1].rn; TREE[RT].LM=tree[rt<<1].LM; Tree[rt].rm=tree[rt<<1|1].rm; TREE[RT].NM=max (tree[rt<<1].nm,tree[rt<<1|1].nm); if(tree[rt<<1].rn<tree[rt<<1|1].ln) {if(tree[rt].lm==tree[rt<<1].len) Tree[rt].lm+=tree[rt<<1|1].LM; if(tree[rt].rm==tree[rt<<1|1].len) tree[rt].rm+=tree[rt<<1].rm; TREE[RT].NM=max (tree[rt].nm,tree[rt<<1].rm+tree[rt<<1|1].lm); }}voidBuildintLintRintRT) {TREE[RT].L=M; TREE[RT].R=R; Tree[rt].len=r-l+1; if(l==r) {TREE[RT].LM=tree[rt].rm=tree[rt].nm=1; Tree[rt].ln=tree[rt].rn=Num[l]; return; } intMid= (l+r) >>1; Build (Lson); Build (Rson); Pushup (RT);}voidUpdateintPosintXintLintRintRT) { if(l==pos&&r==POS) {Tree[rt].ln=tree[rt].rn=x; return; } intMid= (l+r) >>1; if(pos<=mid) Update (Pos,x,lson); ElseUpdate (Pos,x,rson); Pushup (RT);}intQueryintLintRintLintRintRT) { if(l==l&&r==R)returntree[rt].nm; intMid= (l+r) >>1; if(r<=mid)returnquery (L,r,lson); Else if(l>mid)returnquery (L,r,rson); Else { intLl=query (L,mid,lson), ans=0; intRr=query (mid+1, R,rson); if(tree[rt<<1].rn<tree[rt<<1|1].ln) ans=min (mid-l+1,tree[rt<<1].RM) +min (r-mid,tree[rt<<1|1].lm); returnMax (Ans,max (LL,RR)); }}/*int query (int l,int r,int i)//query the largest lcis{if (tree[i].l>=l && tree[i].r<=r) {return tree[i]. Nm } int mid = (TREE[I].L+TREE[I].R) >>1,ans = 0; if (l<=mid) ans = max (ans,query (l,r,2*i)); if (r>mid) ans = max (ans,query (l,r,2*i+1)); if (Tree[2*i].rn < tree[2*i+1].ln) ans = max (ans, min (mid-l+1,tree[2*i].rm) +min (R-MID,TREE[2*I+1].LM)); return ans;}*/intMain () {intt,n,m; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); for(intI=1; i<=n; i++) scanf ("%d",&Num[i]); Build (1N1); //cout<<tree[9].nm<<endl; //cout<< "*" <<endl; for(intI=0; i<m; i++) { Charstr[2]; intb; scanf ("%s%d%d",str,&a,&b); if(str[0]=='U') Update (a+1B1N1); Else if(str[0]=='Q') printf ("%d\n", query (A +1, B +1,1N1)); } } return 0;}
Hdu_3308_ Segment Tree _ interval Merging