# Chairman Tree--Seeking static interval K

Source: Internet
Author: User

Example: poj2104 http://poj.org/problem?id=2104

Explanation: http://blog.sina.com.cn/s/blog_6022c4720102w03t.html

Http://seter.is-programmer.com/posts/31907.html

Just based on the above 2 blog read, not yet to write the level of interpretation

`#include <cstdio>#include<algorithm>using namespacestd;Const intn=100001;intl_child[n* -],r_child[n* -],sum[n* -];intN,m,a[n],hash[n],cnt,root[n];intx,y,k;voiddiscrete () {sort (hash+1, hash+n+1); CNT=unique (hash+1, hash+n+1)-(hash+1);  for(intI=1; i<=n;i++) A[i]=lower_bound (hash+1, hash+cnt+1, A[i])-Hash;}intinit () {intx=0, f=1;CharC=GetChar ();  while(c<'0'|| C>'9') {if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intQueryintXintYintLintRintk) {    if(L==R)returnl; intMid=l+r>>1, tmp=sum[l_child[y]]-Sum[l_child[x]]; if(tmp>=k)returnquery (L_CHILD[X],L_CHILD[Y],L,MID,K); Else returnQuery (r_child[x],r_child[y],mid+1, r,k-tmp);}inttot=0;voidBuildintXint&y,intLintRintv) {Sum[y=++tot]=sum[x]+1; if(L==R)return; intMid=l+r>>1; if(v<=mid) {R_child[y]=R_child[x];    Build (L_CHILD[X],L_CHILD[Y],L,MID,V); }    Else{L_child[y]=L_child[x]; Build (R_child[x],r_child[y],mid+1, r,v); }}intMain () {n=init (); m=init ();  for(intI=1; i<=n;i++) A[i]=init (), hash[i]=A[i];    Discrete (); //for (int i=1;i<=n;i++) printf ("%d", A[i]);     for(intI=1; i<=n;i++) Build (root[i-1],root[i],1, Cnt,a[i]);  for(intI=1; i<=m;i++) {x=init (); Y=init (); k=init (); printf ("%d\n", Hash[query (root[x-1],root[y],1, Cnt,k)]); }}`

Chairman Tree--Seeking static interval K

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.