Description
Input Output
10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10
Sample InputNo
Yes 1
No
Yes 1
No
Yes 2
No
Yes 3Sample Output HINT
Notice: The second integer input is the range of weights in the sequence Lim, i.e. 1<=ai (1<=i<=n) <=lim.
Still Chairman tree template, without discretization.
1<=lim<=10000
Source
1#include <iostream>2#include <cstdio>3#include <algorithm>4 #defineN 100000105 using namespacestd;6 intsum[n],root[500010],ls[n],rs[n];7 intN,m,lim,sz;8 voidUpdata (intLintRintXint&y,intv)9 {Teny=++sz; Onesum[y]=sum[x]+1; ALS[Y]=LS[X]; rs[y]=Rs[x]; - if(L==R)return; - intMid= (l+r) >>1; the if(v<=mid) Updata (l,mid,ls[x],ls[y],v); - ElseUpdata (mid+1, r,rs[x],rs[y],v); - } - + intQueryintLintR) - { + intL=1, r=n,temp= (r-l+1) >>1, x=root[l-1],y=Root[r],mid; A while(l<R) at { - if(sum[y]-sum[x]<=temp)return 0; -Mid= (l+r) >>1; - if(sum[ls[y]]-sum[ls[x]]>temp) - { -R=mid; X=LS[X]; y=Ls[y]; in } - Else if(sum[rs[y]]-sum[rs[x]]>temp) to { +L=mid+1, X=rs[x]; y=Rs[y]; - } the Else return 0; * } $ returnl;Panax Notoginseng } - the intMain () + { Ascanf"%d%d",&n,&m); the for(intI=1; i<=n;i++) + { - intA; $scanf"%d",&a); $Updata (1, n,root[i-1],root[i],a); - } - //scanf ("%d", &m); the for(intI=1; i<=m;i++) - {Wuyi intAA,BB; thescanf"%d%d",&aa,&BB); - intpos=query (AA,BB); Wuprintf"%d\n", POS); - //if (pos==0) printf ("no\n"); About //Else printf ("Yes%d\n", POS); $ } - return 0; -}
View Code
"bzoj2223/3524" [Coci 2009]patuljci