Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=2852

View Code
 1 //2852
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5
6 const int N=100010,maxn=100000;
7 int c[N];
8 int lowbit(int x)
9 {
10 return x&(-x);
11 }
12 int sum(int x)
13 {
14 int s=0;
15 for(int i=x;i>0;i-=lowbit(i)) s+=c[i];
16 return s;
17 }
18 int main()
19 {
20 int m;
21 while(~scanf("%d",&m))
22 {
23 memset(c,0,sizeof(c));
24 while(m--)
25 {
26 int op;
27 scanf("%d",&op);
28 if(op==0)
29 {
30 int x;
31 scanf("%d",&x);
32 for(int i=x;i<maxn;i+=lowbit(i)) c[i]++;
33 }
34 else if(op==1)
35 {
36 int x;
37 scanf("%d",&x);
38 int s=sum(x)-sum(x-1);
39 if(s) for(int i=x;i<maxn;i+=lowbit(i)) c[i]--;
40 else printf("No Elment!\n");
41 }
42 else
43 {
44 int x,k;
45 scanf("%d%d",&x,&k);
46 k+=sum(x);
47 int l=1, r=maxn-1;
48 while(l<r)
49 {
50 int m=(l+r)>>1;
51 if(sum(m)<k) l=m+1;
52 else r=m;
53 }
54 if(sum(l)<k) printf("Not Find!\n");
55 else printf("%d\n",l);
56 }
57 }
58 }
59 return 0;
60 }

 

posted on 2012-03-28 15:28  Qiuqiqiu  阅读(183)  评论(0编辑  收藏  举报