标签:rip art struct ssi let values namespace tput span
Time Limit: 20000MS | Memory Limit: 65536K | |
Total Submissions: 51440 | Accepted: 17594 | |
Case Time Limit: 2000MS |
Description
Input
Output
Sample Input
7 3 1 5 2 6 3 7 4 2 5 3 4 4 1 1 7 3
Sample Output
5 6 3
Hint
Source
document:
1.http://blog.csdn.net/metalseed/article/details/8045038
2.http://www.cnblogs.com/oyking/p/3230296.html
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N=1e5+5; int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } int n,m,mp[N],l,r,k; struct data{ int v,id; bool operator <(const data &r)const{return v<r.v;} }a[N]; struct node{ int lc,rc,size; }t[N*20]; int cnt=0,root[N]; void insert(int num,int &x,int l,int r){//printf("ins %d %d %d\n",l,r,x); cnt++; t[cnt]=t[x];x=cnt; ++t[x].size; if(l==r) return; int mid=(l+r)>>1; if(num<=mid) insert(num,t[x].lc,l,mid); else insert(num,t[x].rc,mid+1,r); } int ins(int num,int pre,int l,int r){ int x=++cnt; t[x]=t[pre]; ++t[x].size; if(l==r) return x; int mid=(l+r)>>1; if(num<=mid) t[x].lc=ins(num,t[x].lc,l,mid); else t[x].rc=ins(num,t[x].rc,mid+1,r); return x; } int query(int i,int j,int l,int r,int k){ if(l==r) return l; int ls=t[t[j].lc].size-t[t[i].lc].size; int mid=(l+r)>>1; if(k<=ls) return query(t[i].lc,t[j].lc,l,mid,k); else return query(t[i].rc,t[j].rc,mid+1,r,k-ls); } int main(){ n=read();m=read(); for(int i=1;i<=n;i++) a[i].v=read(),a[i].id=i; sort(a+1,a+1+n); for(int i=1;i<=n;i++) mp[a[i].id]=i; for(int i=1;i<=n;i++){ //root[i]=ins(mp[i],root[i-1],1,n); root[i]=root[i-1]; insert(mp[i],root[i],1,n); } while(m--){ l=read();r=read();k=read(); printf("%d\n",a[query(root[l-1],root[r],1,n,k)].v); } }
标签:rip art struct ssi let values namespace tput span
原文地址:http://www.cnblogs.com/candy99/p/6160704.html