标签:lease scanf sub map queue 线段树 present cstring contain
Time Limit: 20000MS | Memory Limit: 65536K | |
Total Submissions: 55456 | Accepted: 19068 | |
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
#include<iostream> #include<fstream> #include<cstdio> #include<algorithm> #include<string> #include<vector> #include<queue> #include<deque> #include<utility> #include<map> #include<set> #include<cmath> #include<cstdlib> #include<ctime> #include<functional> #include<sstream> #include<cstring> #include<bitset> #include<stack> using namespace std; int n,m,x,y,z,size; int kkk[100005],root[5000005],lef[5000005],rig[5000005],sum[5000005]; struct sdt { int num,id; }a[100005]; bool cmp(sdt x,sdt y) { return x.num<y.num; } void build(int l,int r,int pre,int &now,int v) { now=++size; sum[now]=sum[pre]+1; if(l==r)return ; lef[now]=lef[pre]; rig[now]=rig[pre]; int mid=(l+r)/2; if(v<=mid)build(l,mid,lef[pre],lef[now],v); else build(mid+1,r,rig[pre],rig[now],v); } int query(int l,int r,int v) { int ll=root[l-1],rr=root[r]; int L=1,R=n,mid; while(L!=R) { mid=(L+R)/2; if(sum[lef[rr]]-sum[lef[ll]]>=v) { R=mid; ll=lef[ll]; rr=lef[rr]; } else { v-=(sum[lef[rr]]-sum[lef[ll]]); L=mid+1; ll=rig[ll]; rr=rig[rr]; } } return L; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i].num); a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++)kkk[a[i].id]=i; for(int i=1;i<=n;i++)build(1,n,root[i-1],root[i],kkk[i]); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); printf("%d\n",a[query(x,y,z)].num); } return 0; }
标签:lease scanf sub map queue 线段树 present cstring contain
原文地址:http://www.cnblogs.com/winmt/p/6664111.html