You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
typedef long long LL;
using namespace std;
const int N = 100010;
// 树状数组模板
typedef long long LL;
#define lowbit(x) (x & -x)
int c[N];
void add(int x, int d) {
for (int i = x; i < N; i += lowbit(i)) c[i] += d;
}
LL sum(int x) {
LL res = 0;
for (int i = x; i; i -= lowbit(i)) res += c[i];
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("HDU2852.in", "r", stdin);
#endif
// 加快读入
ios::sync_with_stdio(false), cin.tie(0);
int m;
while (cin >> m) {
memset(c, 0, sizeof c);
while (m--) {
int op;
cin >> op;
if (op == 0) {
int x;
cin >> x;
add(x, 1);
} else if (op == 1) {
int x;
cin >> x;
if (sum(x) - sum(x - 1) == 0)
puts("No Elment!");
else
add(x, -1);
} else {
int a, k;
cin >> a >> k;
int x = sum(a);
if (sum(N - 1) - x < k) // 剩余数量不足K个
puts("Not Find!");
else {
int l = 1, r = N - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (sum(mid) - x >= k)
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
}
}
}
}
return 0;
}