标签:update lan int question width date main quick include
Time Limit: 20000MS | Memory Limit: 65536K | |
Total Submissions: 60557 | Accepted: 21228 | |
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
1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <queue> 5 #include <iostream> 6 #include "algorithm" 7 using namespace std; 8 typedef long long LL; 9 const int MAX=1e5+5; 10 int n,m; 11 int a[MAX],b[MAX],lb,root[MAX],cnt; 12 struct Node{ 13 int l,r; 14 int sum; 15 Node (){l=r=sum=0;} 16 }t[MAX*40]; 17 inline int read(){ 18 int an=0,x=1;char c=getchar(); 19 while (c<‘0‘ || c>‘9‘) {if (c==‘-‘) x=-1;c=getchar();} 20 while (c>=‘0‘ && c<=‘9‘) {an=an*10+c-‘0‘;c=getchar();} 21 return an*x; 22 } 23 void update(int l,int r,int &x,int y,int pos){ 24 t[++cnt]=t[y],t[cnt].sum++;x=cnt; 25 if (l==r) return; 26 int mid=(l+r)>>1; 27 if (pos<=mid) update(l,mid,t[x].l,t[y].l,pos); 28 else update(mid+1,r,t[x].r,t[y].r,pos); 29 } 30 int query(int l,int r,int x,int y,int k){ 31 if (l==r) return l; 32 int sum=t[t[y].l].sum-t[t[x].l].sum; 33 int mid=(l+r)>>1; 34 if (sum>=k) return query(l,mid,t[x].l,t[y].l,k); 35 else return query(mid+1,r,t[x].r,t[y].r,k-sum); 36 } 37 int main(){ 38 freopen ("chairman.in","r",stdin); 39 freopen ("chairman.out","w",stdout); 40 int i,j; 41 int x,y,z; 42 n=read();m=read(); 43 for (i=1;i<=n;i++){a[i]=read();b[i]=a[i];}sort(b+1,b+n+1); 44 lb=unique(b+1,b+n+1)-(b+1); 45 for (i=1;i<=n;i++){ 46 int pos=lower_bound(b+1,b+lb+1,a[i])-b; 47 update(1,lb,root[i],root[i-1],pos); 48 } 49 for (i=1;i<=m;i++){ 50 x=read();y=read();z=read(); 51 printf("%d\n",b[query(1,lb,root[x-1],root[y],z)]); 52 } 53 return 0; 54 }
标签:update lan int question width date main quick include
原文地址:http://www.cnblogs.com/keximeiruguo/p/7599755.html