-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2243.cpp
90 lines (74 loc) · 1.76 KB
/
2243.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <string>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <set>
#define p(a, b) make_pair(a, b)
#define SWAP(a, b, type) do { \
type temp; \
temp = a; \
a = b; \
b = temp; \
} while (0)
#define INF 1000000000
#define MAX 1000000
#define endl '\n'
#define ll long long
using namespace std;
vector<ll> seg;
int arr[MAX+5];
void update(int Node, int Start, int End,int index, int diff){
if(Start > index || End < index) return;
seg[Node]+=diff;
if(Start!=End){
int Mid = (Start + End)/2;
update(Node * 2, Start, Mid, index, diff);
update(Node * 2 + 1, Mid + 1, End, index, diff);
}
}
void input() {
}
void init() {
}
int query(int Node, int Start, int End, int Cnt){
if(Start == End) return Start;
int Mid = (Start + End)/2;
if(seg[Node * 2]>=Cnt) return query(Node * 2,Start,Mid,Cnt);
return query(Node * 2 + 1,Mid + 1,End, Cnt - seg[Node * 2]);
}
void solution() {
int N; cin>>N;
int command,a,b,pos, diff;
int Height = (int)ceil(log2(MAX));
//cout<< (1<<(Height+1));
int Tree_Size = 1 << (Height + 1);
seg.resize(Tree_Size);
for(int i=0;i<N;i++){
cin>>command;
if(command == 2){
cin>>a>>b;
arr[a] += b;
update(1, 1, MAX, a, b);
}else{
cin>>a;
pos = query(1, 1, MAX, a);
cout<<pos<<'\n';
arr[pos]--;
update(1, 1, MAX, pos, -1);
}
}
//for(int i=1;i<=3;i++) cout<<arr[i]<<' ';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
input();
solution();
return 0;
}