rembocoder

Untitled

Apr 19th, 2023
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. const int inf = 2e18;
  8. const int mod = 1e9 + 7;
  9.  
  10. int32_t main() {
  11.     ios_base::sync_with_stdio(0);
  12.     cin.tie(0); cout.tie(0);
  13.     int n;
  14.     cin >> n;
  15.     vector<int> a(n);
  16.     for (int i = 0; i < n; i++) {
  17.         cin >> a[i];
  18.     }
  19.     vector<int> b = a;
  20.     set<int> pos;
  21.     for (int i = 0; i < n; i++) {
  22.         pos.insert(i);
  23.     }
  24.     int m;
  25.     cin >> m;
  26.     while (m--) {
  27.         int t;
  28.         cin >> t;
  29.         if (t == 2) {
  30.             int i;
  31.             cin >> i;
  32.             i--;
  33.             cout << a[i] - b[i] << '\n';
  34.             continue;
  35.         }
  36.         int i, x;
  37.         cin >> i >> x;
  38.         i--;
  39.         while (x > 0) {
  40.             auto it = pos.lower_bound(i);
  41.             if (it == pos.end()) {
  42.                 break;
  43.             }
  44.             i = *it;
  45.             int cur = min(b[i], x);
  46.             b[i] -= cur;
  47.             x -= cur;
  48.             if (b[i] == 0) {
  49.                 pos.erase(i);
  50.             }
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment