题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2852
题目大意:
3种操作: 0 x ,把x压进容器。
1 x,把x从容器中删除一个。
2 a b,查询容器中所有数比a大的第b小的数。
(这里就不吐槽题面了)
解题思路:主席树做,因为所有的数都<=1e5,不用离散化,直接搞。
查询那里利用树状数组判断一下先。
/* ***********************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆ ┃ 勒 ┃ ┆
┆ ┃ 戈 ┗━━━┓ ┆
┆ ┃ 壁 ┣┓┆
┆ ┃ 的草泥马 ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std;
#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}
const int N = 1e5 + 5;
int bit[N],num[N];
int n;
int lowbit(int x) {return x&-x;};
void add(int i,int x)
{
while(i<=N)
{
bit[i] += x;
i += lowbit(i);
}
}
int Sum(int i)
{
int s = 0;
while(i>0)
{
s += bit[i];
i -= lowbit(i);
}
return s;
}
struct node
{
int l,r,sum;
}tree[N*20];
int tot,cnt;
int rt[N];
void build(int l,int r,int &x)
{
x = ++tot;
tree[x].sum = 0;
if(l==r) return;
int mid = (l+r) >> 1;
build(l,mid,tree[x].l);
build(mid+1,r,tree[x].r);
}
void update(int l,int r,int &x,int y,int k,int val)
{
x = ++tot;
tree[x] = tree[y]; tree[x].sum += val;
if(l==r) return;
int mid = (l+r) >> 1;
if(k<=mid) update(l,mid,tree[x].l,tree[y].l,k,val);
else update(mid+1,r,tree[x].r,tree[y].r,k,val);
}
int query(int l,int r,int x,int y,int k)
{
if(l==r) return l;
int mid = (l+r) >> 1;
int sum = tree[tree[y].l].sum - tree[tree[x].l].sum;
if(k<=sum) return query(l,mid,tree[x].l,tree[y].l,k);
else return query(mid+1,r,tree[x].r,tree[y].r,k-sum);
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
while(~scanf("%d",&n))
{
MS0(num);
MS0(bit);
tot = cnt = 0;
int now = 1;
build(1,N,rt[0]);
int op;
for(int i=1;i<=n;i++)
{
op = read();
if(op==0)
{
cnt++;
int x = read();
num[x]++;
add(x,1);
update(1,N,rt[now],rt[now-1],x,1);
now++;
}
else if(op==1)
{
int x = read();
if(num[x]!=0)
{
cnt--;
add(x,-1);
update(1,N,rt[now],rt[now-1],x,-1);
num[x]--;
now++;
}
else printf("No Elment!\n");
}
else
{
int a,b;
a = read(), b = read();
int res = Sum(a);
if(res + b > cnt) printf("Not Find!\n");
else printf("%d\n",query(1,N,rt[0],rt[now-1],res + b));
}
}
}
return 0;
}