找比k大的数,可以加上k前面的个数,然后转化为求第k大数

把数作为下标,然后维护小于x的数的个数,然后查找的时候二分即可,时间复杂度O(n*logn*logn)

当然如果用线段树是可以达到O(nlogn)的。。不过这题的意图是BIT,而且还放宽了时限。。




#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define eps 1e-8
#define inf 1000000007
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define ls T[i<<1]
#define rs T[i<<1|1]
#define op T[i]
#define mid (x+y>>1)
#define NM 100005
#define nm 2000005
#define pi 3.141592653
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}


int n,m,T,a[NM],_x,_t;
void mod(int x,int t){for(;x<=n;x+=lowbit(x))a[x]+=t;}
int sum(int x,int s=0){for(;x;x-=lowbit(x))s+=a[x];return s;}

int find(int x){
int l=1,r=n,ans;
if(sum(r)<x)return n+1;
while(l<=r){
int t=l+r>>1;
if(sum(t)>=x){ans=t;r=t-1;}
else l=t+1;
}
return ans;
}

int main(){
//freopen("data.in","r",stdin);
n=1e5;
while(~scanf("%d",&m)){
mem(a);
while(m--){
_t=read();_x=read();
if(_t==0)mod(_x,1);
else if(_t==1){
if(sum(_x)-sum(_x-1)==0)puts("No Elment!");
else mod(_x,-1);
}else{
_x=read()+sum(_x);
//printf("%d\n",_x);
_x=find(_x);
if(_x<=n)printf("%d\n",_x);
else puts("Not Find!");
}
}
}
}






KiKi's K-Number


Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4295    Accepted Submission(s): 1953


Problem Description


For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container, the container is to support the three operations.

Push: Push a given element e to container

Pop: Pop element of a given e from container

Query: Given two elements a and k, query the kth larger number which greater than a in container;

Although Kiki is very intelligent, she can not think of how to do it, can you help her to solve this problem?


 



Input


Input some groups of test data ,each test data the first number is an integer m (1 <= m <100000), means that the number of operation to do. The next m lines, each line will be an integer p at the beginning, p which has three values:
If p is 0, then there will be an integer e (0 <e <100000), means press element e into Container.

If p is 1, then there will be an integer e (0 <e <100000), indicated that delete the element e from the container  

If p is 2, then there will be two integers a and k (0 <a <100000, 0 <k <10000),means the inquiries, the element is greater than a, and the k-th larger number.


 



Output


For each deletion, if you want to delete the element which does not exist, the output "No Elment!". For each query, output the suitable answers in line .if the number does not exist, the output "Not Find!".


 



Sample Input


5 0 5 1 2 0 6 2 3 2 2 8 1 7 0 2 0 2 0 4 2 1 1 2 1 2 2 1 3 2 1 4


 



Sample Output


No Elment! 6 Not Find! 2 2 4 Not Find!


 



Source


​2009 Multi-University Training Contest 4 - Host by HDU ​


 



Recommend


gaojie   |   We have carefully selected several similar problems for you:   ​​2846​​​  ​​​2838​​​  ​​​2845​​​  ​​​2851​​​  ​​​2850​​ 


 



​Statistic​​ | 

​Submit​​ | 

​Discuss​​ |

​Note​