Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <unordered_map>
- #include <numeric>
- #include <iomanip>
- using namespace std;
- #define pii pair<long long, long long>
- #define ll long long
- #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
- const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
- const long long dl[2] = {1, -1};
- const long long MOD = 1000000007;
- const long long MAXN = 1000005;
- int M;
- int seg[MAXN * 4];
- void update(int x, int s, int e, int idx, int up){
- if(idx < s or idx > e) return;
- if(s == e and s == idx){
- seg[x] += up;
- return;
- }
- int mid = (s + e) / 2;
- update(x * 2, s, mid, idx, up);
- update(x * 2 + 1, mid + 1, e, idx, up);
- seg[x] = seg[x * 2] + seg[x * 2 + 1];
- }
- int query(int x, int s, int e, int n){
- if(s == e){
- return s;
- }
- int mid = (s + e) / 2;
- if(seg[x * 2] >= n){
- return query(x * 2, s, mid, n);
- }
- else{
- return query(x * 2 + 1, mid + 1, e, n - seg[x * 2]);
- }
- }
- int main() {
- FAST;
- cin >> M;
- for(int a, b, c, i = 0; i < M; i++){
- cin >> a;
- if(a == 1){
- cin >> b;
- int q = query(1, 1, 1000000, b);
- cout << q << "\n";
- update(1, 1, 1000000, q, -1);
- }
- else{
- cin >> b >> c;
- update(1, 1, 1000000, b, c);
- }
- }
- }
- /*
- 6
- 2 1 2
- 2 3 3
- 1 2
- 1 2
- 2 1 -1
- 1 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement