The force on the team + line tree is obviously t.
If the team did not remove the transfer words ... You can use and check the set instead of the segment tree.
So according to the general posture will be asked to sort, the right end point as usual, the left end of each end from the end of the block to start running, after running the violence withdrawn.
Complexity or O (m*n^0.5)
In order to be able to withdraw and check the merger, a temporary increase in the point for the father.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 Const intmaxn=50233;8 structzs{intL,r,id;} Q[MAXN];9 intFa[maxn],sz[maxn],mp[maxn],st[maxn],top;Ten intB[MAXN],AN[MAXN]; One intI,j,k,n,m,ans; A - intRaCharRx; -InlineintRead () { theRx=getchar (), ra=0; - while(rx<'0'|| Rx>'9') rx=GetChar (); - while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } + -InlineintGETFA (intx) {returnfa[x]!=x?fa[x]=GETFA (fa[x]): x;} +InlineintGet1 (intx) { while(fa[x]!=x) x=fa[x];returnx;} A atInlinevoidAddintx) { -sz[x]=1; - intPRE=GETFA (x1), AFT=GETFA (x+1); - if(Sz[pre]) sz[pre]+=sz[x],fa[x]=pre,x=Pre; - if(Sz[aft]) sz[aft]+=sz[x],fa[x]=aft,x=aft; - if(Sz[x]>ans) ans=Sz[x]; in } -InlinevoidADD2 (intx) { tosz[x]=1; + intPre=get1 (x1), Aft=get1 (x+1); - the if(Sz[pre]) *sz[x]+=sz[pre],fa[pre]=x,st[++top]=Pre; $ if(Sz[aft])Panax Notoginsengsz[x]+=sz[aft],fa[aft]=x,st[++top]=aft; - if(Sz[x]>ans) ans=Sz[x]; the } + A BOOLCMP (ZS A,zs b) {returnb[a.l]<b[b.l]| | (b[a.l]==b[b.l]&&a.r<B.R);} the + intMain () { -N=read (), M=read ();intKuai= (int) sqrt (n1.2)+3; $ for(i=1; i<=n;i++) Mp[i]=read (), b[i]= (i+kuai-1)/Kuai; $ for(i=1; i<=m;i++) Q[i].l=read (), Q[i].r=read (), q[i].id=i; -Sort (q+1, q+1+m,cmp); - intr,r1,now,tmp; the for(i=1; i<=m;) { - for(R=i; b[q[r].l]==b[q[i].l];r++); r--;Wuyir1=b[q[i].l]==b[n]?n:b[q[i].l]*Kuai; the for(j=0; j<=n+1; j + +) fa[j]=j,sz[j]=0; -ans=0, now=r1+1; Wu - for(j=i;j<=r;j++){ About while(NOW<=Q[J].R) Add (mp[now++]); $tmp=ans,top=0; - for(k=q[j].l;k<=q[j].r&&k<=r1;k++) ADD2 (Mp[k]); -an[q[j].id]=ans; - while(top) fa[st[top]]=st[top],top--; A for(k=q[j].l;k<=q[j].r&&k<=r1;k++) fa[mp[k]]=mp[k],sz[mp[k]]=0; +ans=tmp; the } -i=r+1; $ } the for(i=1; i<=m;i++) printf ("%d\n", An[i]); the}
View Code
[bzoj4358] Permu