-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1289.cpp
49 lines (40 loc) · 1.06 KB
/
1289.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e6;
int tree[MAX*4];
int query(int s, int e, int node, int rank) {
if (s == e) return s;
int m = (s+e)/2;
if (tree[node*2] >= rank) return query(s, m, node*2, rank);
else return query(m+1, e, node*2+1, rank-tree[node*2]);
}
void update(int s, int e, int node, int index, int diff) {
if (e < index || index < s) return;
tree[node] += diff;
if (s == e) return;
int m = (s+e)/2;
update(s, m, node*2, index, diff);
update(m+1, e, node*2+1, index, diff);
}
void solve(){
int N; cin >> N;
for (int i = 0; i < N; i++) {
int a; cin >> a;
if (a != 1) {
int b,c; cin >> b>>c;
update(1,MAX,1,b,c);
} else {
int b; cin >> b;
int result = query(1, MAX, 1, b);
cout << result << '\n';
update(1,MAX,1,result,-1);
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}