The subject is neither RMQ nor simple (to me this konjac konjac)
At first can only think of tree sets of tree cover tree tat and then looked at the data range decisive roll to worship the puzzle.
Then we know that a pre-order can get rid of a log. But it has to be written. Durable segment tree sets can persist segment trees.
Then the pleasure of the Open code ... Moving is not even need to adjust ... What's more touching is to hand it directly to tle.
Then from the Internet to find someone else's code (the same way) found the same data I want to run 6s+. Nominal as long as 2s+.
After the various Kathang is still one times slower tat ... At last, write your own Max function just as fast as the standard. Tat, how come these days are always out of the strange situation qaq.
The original story should have ended here. When the evaluation, and even the title is good: "A max function caused by tragedy"
However, the hand-over is still tle (lift table ... And then found that the standard is also tle ...
And then think of the beginning of the scope array range of open: After looking at the next hint. Sure enough, the data has been strengthened by many people.
Probably the end is to write a tree set of trees in the tle ...... Boss to a dozen blades?
Code directly attached to Tle
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn=100233;7 structpoi{8 intPos,pr,af,num;9 }A[MAXN];Ten intPR[MAXN],AF[MAXN]; One intrt_out[maxn],rt[maxn* -],lc[maxn* -],rc[maxn* -],tt; A intmx[ -*maxn],l[ -*maxn],r[ -*Maxn],tot; - intI,j,n,m,l,r,lastans,v,v1; - the intRaCharRx; -InlineintRead () { -Rx=getchar (), ra=0; - while(rx<'0'|| Rx>'9') rx=GetChar (); + while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } + Charqaq[7];intLen; AInlinevoidOutxintx) { at if(!x) {Puts ("0");return;} - while(x) qaq[len++]=x%Ten, x/=Ten; - while(len) Putchar (qaq[--len]+'0');p Utchar ('\ n'); - } -InlineintMaxintXintY) {returnX<y?y:x;} - in -InlinevoidInsintPreint&x,intLintR) { tox=++tot,mx[x]=Mx[pre]; + if(A[i].num>mx[x]) mx[x]=A[i].num; - if(L==R)return; theRegisterintMid= (l+r) >>1; * if(V<=mid) r[x]=R[pre],ins (l[pre],l[x],l,mid); $ ElseL[x]=l[pre],ins (r[pre],r[x],mid+1, R);Panax Notoginseng } - intZs; theInlineintGETMX (intXintLintRintCintd) { + if(!x)return 0; A if(C<=L&&D>=R)returnMx[x];registerintMid= (l+r) >>1; the if(C>mid)returnGETMX (r[x],mid+1, r,c,d);Else + if(D<=mid)returnGETMX (L[X],L,MID,C,D);Else - returnMax (GETMX (l[x],l,mid,c,d), GETMX (r[x],mid+1, R,c,d)); $ $ } - - the - WuyiInlinevoidInsertintPreint&x,intLintR) { theX=++tt,ins (Rt[pre],rt[x],1, n); - if(L==R)return; WuRegisterintMid= (l+r) >>1; - if(V1<=mid) rc[x]=Rc[pre],insert (lc[pre],lc[x],l,mid); About ElseLc[x]=lc[pre],insert (rc[pre],rc[x],mid+1, R); $ } -InlineintQueryintXintLintRintCintd) { - if(!x)return 0; - if(C<=L&&D>=R)returnGETMX (Rt[x],1, n,l,r); ARegisterintMid= (l+r) >>1; + if(C>mid)returnQuery (rc[x],mid+1, r,c,d); the Else returnMax (GETMX (rt[rc[x]),1, N,l,r), query (lc[x],l,mid,c,d)); - } $ the the the the BOOLCMP (POI A,poi b) {returna.pr<b.pr;} - intMain () { inN=read (), m=read (); the for(i=1; i<=n;i++) A[i].pos=i,a[i].pr=pr[a[i].num=read ()],pr[a[i].num]=i; the for(i=n;i;i--) A[i].af=af[a[i].num]?af[a[i].num]:(n+1), af[a[i].num]=i; AboutSort (A +1, A +1+n,cmp); the for(i=1; i<=n;i++) V=a[i].pos,v1=a[i].af,insert (rt_out[i-1],rt_out[i],1, n+1); the for(i=1; i<=m;i++){ theL=read () +lastans,r=read () +Lastans; + if(l>=n) L%=n;if(r>=n) r%=N; -l++,r++;if(l>R) Swap (l,r); theRegisterintL=1, r=N,mid;Bayi for(l<r;a[mid].pr<l?) (l=mid):(r=mid-1)) mid= (l+r+1) >>1; theLastans=query (Rt_out[l],1, n+1, r+1, n+1); the Outx (Lastans); - } - return 0; the}
View Code
[bzoj3489] A Simple RMQ problem