标签:color nod namespace == roo lan out node space
传送
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int cnt=0,original_value[9000001]={0},a[9000001]={0},root[9000001]={0}; 7 struct node{ 8 int val,l,r; 9 }tree[9000001]; 10 struct Node{ 11 int id,val; 12 }original[9000001]; 13 int cmp(Node x,Node y){ 14 return x.val<y.val; 15 } 16 int build(int x,int l,int r){ 17 x=++cnt; 18 if(l==r) return x; 19 int mid=(l+r)/2; 20 tree[x].l=build(0,l,mid); 21 tree[x].r=build(0,mid+1,r); 22 return x; 23 } 24 int New(int x){ 25 tree[++cnt]=tree[x]; 26 tree[cnt].val=tree[x].val+1; 27 return cnt; 28 } 29 int turn(int x,int pos,int l,int r){ 30 x=New(x); 31 if(l==r) return x; 32 int mid=(l+r)/2; 33 if(pos<=mid) tree[x].l=turn(tree[x].l,pos,l,mid); 34 else tree[x].r=turn(tree[x].r,pos,mid+1,r); 35 return x; 36 } 37 int search(int x,int y,int pos,int l,int r){ 38 if(l==r) return l; 39 int mid=(l+r)/2; 40 if(pos<=tree[tree[y].l].val-tree[tree[x].l].val) 41 return search(tree[x].l,tree[y].l,pos,l,mid); 42 else return search(tree[x].r,tree[y].r,pos-(tree[tree[y].l].val-tree[tree[x].l].val),mid+1,r); 43 } 44 int main(){ 45 //freopen("P3834_6.in","r",stdin); 46 //freopen("hhh.out","w",stdout); 47 int n,m; 48 scanf("%d%d",&n,&m); 49 for(int i=1;i<=n;i++){ 50 scanf("%d",&original[i].val); 51 original[i].id=i; 52 } 53 sort(original+1,original+n+1,cmp); 54 int N=1; 55 a[original[1].id]=N; 56 original_value[N]=original[1].val; 57 for(int i=2;i<=n;i++){ 58 if(original[i].val!=original[i-1].val) N++; 59 original_value[N]=original[i].val; 60 a[original[i].id]=N; 61 } 62 root[0]=build(0,1,N); 63 for(int i=1;i<=n;i++) root[i]=turn(root[i-1],a[i],1,N); 64 while(m--){ 65 int L,R,K; 66 scanf("%d%d%d",&L,&R,&K); 67 int ans=original_value[search(root[L-1],root[R],K,1,N)]; 68 printf("%d\n",ans); 69 } 70 return 0; 71 }
标签:color nod namespace == roo lan out node space
原文地址:https://www.cnblogs.com/latent-Lin/p/14345338.html