- #include
- #definelowbit(i) (i&(-i))using namespace std;
- const intmaxn = 1e5+1;
- int c[maxn];
- inline voidadd(inti,int val)
- {
- while(i<=100000){
- c[i] += val;
- i += lowbit(i);
- }
- }
- intsum(int i)
- {
- intans =0;
- while(i>0){
- ans += c[i];
- i -= lowbit(i);
- }
- return ans;
- }
- int vis[maxn];
- intBin_search(intL,intR,intkey,int index)
- {
- int mid;
- while(L < R){
- mid = L + ((R-L)>>1);
- if(sum(mid) - sum(index) < key) L = mid +1;
- elseR = mid;
- }
- return R;
- }
- intmain(void)
- {
- int n;
- while(~scanf("%d", &n) && n){
- memset(c, 0,sizeof(c));
- memset(vis, 0,sizeof(vis));
- int command;
- inttot =0;
- intM =0;
- for(intt=1; t<=n; t++){
- scanf("%d", &command);
- if(command==0){
- int temp;
- scanf("%d", &temp);
- if(temp>M) M = temp;
- vis[temp]++;
- add(temp, 1);
- tot++;
- }
- else if(command==1){
- int temp;
- scanf("%d", &temp);
- if(vis[temp]){
- tot--;
- add(temp, -1);
- vis[temp]--;
- }else{
- puts("No Elment!");
- }
- }
- else{
- int a, b;
- int ans;
- scanf("%d%d", &a, &b);
- if(tot-sum(a) >= b){
- intans = Bin_search(a, M, b, a);
- printf("%d\n", ans);
- }else{
- puts("Not Find!");
- }
- }
- }
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2092842.html