标签:des style blog http color os strong io
Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h> 10 #include<string> 11 #include<cmath> 12 using namespace std; 13 #define pb push_back 14 int p[101010],m,mm; 15 void update(int pos,int num){ 16 while(pos>0){ 17 p[pos]+=num; 18 pos-=pos&(-pos); 19 } 20 } 21 int getnum(int pos){ 22 int sum=0; 23 while(pos<=100000){ 24 sum+=p[pos]; 25 pos+=pos&(-pos); 26 } 27 return sum; 28 } 29 void Find(int pos,int k){ 30 int l=pos+1,r=100000,mid,mm=10000000,be=getnum(pos+1); 31 while(l<=r){ 32 mid=(l+r)/2; 33 int tmp=be-getnum(mid); 34 if(tmp<k) l=mid+1; 35 else{ 36 mm=min(mm,mid-1); 37 r=mid-1; 38 } 39 } 40 if(mm!=10000000) printf("%d\n",mm); 41 else printf("Not Find!\n"); 42 43 } 44 int main(){ 45 #ifndef ONLINE_JUDGE 46 freopen("input.txt","r" ,stdin); 47 #endif // ONLINE_JUDGE 48 while(cin>>m){ 49 memset(p,0,sizeof(p)); 50 while(m--){ 51 int a,b,c; 52 scanf("%d",&a); 53 if(a==0){ 54 scanf("%d",&b); 55 update(b,1); 56 } 57 if(a==1){ 58 scanf("%d",&b); 59 if(getnum(b)-getnum(b+1)>0) update(b,-1); 60 else printf("No Elment!\n"); 61 } 62 if(a==2){ 63 scanf("%d%d",&b,&c); 64 Find(b,c); 65 } 66 } 67 } 68 }
hdu 2852 KiKi's K-Number,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ainixu1314/p/3888986.html