You can persist line tree template problems.
#include <iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<vector>using namespacestd;intn,q,tot,a[110000];introot[2100000],left[2100000],right[2100000];intval[2100000];voidInsert (Const intLConst intRConst introot_l,int& Root_r,Const intd) {Val[root_r=++tot]=val[root_l]+1; if(L==R)return ; intmid=l+ (r-l) >>1); if(d<=mid) {Right[root_r]=right[root_l]; Insert (L,MID,LEFT[ROOT_L],LEFT[ROOT_R],D); } Else{Left[root_r]=left[root_l]; Insert (Mid+1, r,right[root_l],right[root_r],d); } return ;}intQuery (Const intLConst intRConst introot_l,Const intRoot_r,Const intd) { if(L==R)returnl; intmid=l+ (r-l) >>1), temp; Temp=val[left[root_r]]-val[left[root_l]]; if(Temp>=d)returnQuery (l,mid,left[root_l],left[root_r],d); returnQuery (mid+1, r,right[root_l],right[root_r],d-temp);}intMain () {Freopen ("inch","R", stdin); inti; Vector<int>VEC; scanf ("%d%d",&n,&q); for(i=1; i<=n;++i) {scanf ("%d",&A[i]); Vec.push_back (A[i]); } sort (Vec.begin (), Vec.end ()); Vec.erase (Unique (Vec.begin (), Vec.end ()), Vec.end ()); for(i=1; i<=n;++i) {A[i]=lower_bound (Vec.begin (), Vec.end (), A[i])-vec.begin () +1; Insert (1, Vec.size (), root[i-1],root[i],a[i]); } for(i=1; i<=q;++i) {intl,r,k; scanf ("%d%d%d",&l,&r,&k); printf ("%d\n", Vec[query (1, Vec.size (), root[l-1],ROOT[R],K)-1]); } return 0;}
[POJ2104] Interval k large number [interval k large number, can persist line tree template problem]