3个操作:
0:插入
1: 删除,如果没有,则输出 No Elment!
2:查找比a大k个数的数
本来想用堆做,结果优先队列没有弹出任意一个数的操作。只能放弃,看大神都是二分做的。
/* Problem ID: meaning: Analyzing: */ #include <iostream> #include <algorithm> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<vector> #include<queue> using namespace std; typedef struct even{int y1,y2,x;}even; #define clr(A,k) memset(A,k,sizeof(A)) #define FOR(i,s,t) for(int i=(s); i<(t); i++) #define LL long long #define BUG puts("here!!!") #define print(x) printf("%d\n",x) #define STOP system("pause") #define eps 1e-8 #define PI acos(-1.0) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define maxn 100001 #define lowbit(x) x&(-x) LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;} priority_queue<int>q1; int A[maxn],C[maxn]; void update(int pos,int val){ while(pos<maxn){ C[pos]+=val; pos+=lowbit(pos); } } int query(int x){ int ret=0; while(x>0){ ret+=C[x]; x-=lowbit(x); } return ret; } int binsearch(int a,int k){ int l=a+1; int r=maxn-1; int ans=maxn; int s1=query(a); while(l<=r){ int m=(l+r)>>1; int s2=query(m); if(s2-s1>=k){ r=m-1; if(m<ans) ans=m; } else { l=m+1; } } return ans; } int main(){ int m,op,a,k,e; while(~scanf("%d",&m)){ clr(A,0); clr(C,0); int len=0; while(m--){ scanf("%d",&op); if(op==0){ scanf("%d",&e); if(A[e]==0) update(e,1); } else if(op==1) { scanf("%d",&e); if(query(e)-query(e-1)==0) puts("No Elment!"); else update(e,-1); } else if(op==2){ scanf("%d%d",&a,&k); int ret=binsearch(a,k); if(ret==maxn) puts("Not Find!"); else printf("%d\n",ret); } } } return 0; }