func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, m;   int volume[N];   int amount[N];   int parent[N];   int tofill[N];   int weight[N];   std::set<int> notFull;   void reducePath(int index, int lead) {     while (parent[index] != index) {       int oldParent = parent[index];       parent[index] = lead;       index = oldParent;     }   }   int find(int index) {     int lead = index;     while (parent[lead] != lead) {       lead = parent[lead];     }     reducePath(index, lead);     return lead;   }   bool merge(int l, int r) {     int ll = find(l);     int rl = find(r);     if (ll == rl) {       return false;     }     if (weight[ll] < weight[rl]) swap(ll, rl);     parent[rl] = ll;     weight[ll] += weight[rl];     if (tofill[ll] < tofill[rl]) tofill[ll] = tofill[rl];     return true;   }   void fill(int p, int x) {     while (x > 0) {       int lead = find(p);       int f = tofill[lead];       int remainingVolume = volume[f] - amount[f];       int fillAmount = std::min(remainingVolume, x);       amount[f] += fillAmount;       x -= fillAmount;       if (amount[f] == volume[f]) {         if (f == n - 1)           break;         else           ++f;         merge(lead, f);       }     }   }   void fill2(int p, int x) {     auto lb = notFull.lower_bound(p);     while (x > 0 && lb != notFull.end()) {       int remainingVolume = volume[*lb] - amount[*lb];       int fillAmount = std::min(remainingVolume, x);       amount[*lb] += fillAmount;       x -= fillAmount;       if (amount[*lb] == volume[*lb])         lb = notFull.erase(lb);       else         lb++;     }   }   void init() {     for (int i = 0; i < n; ++i) {       parent[i] = i;       tofill[i] = i;       weight[i] = 1;       notFull.insert(i);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> volume[i];     }     init();     cin >> m;     for (int i = 0; i < m; ++i) {       int q;       cin >> q;       if (q == 1) {         int p, x;         cin >> p >> x;         fill2(--p, x);       } else {         int k;         cin >> k;         cout << amount[--k] <<   n ;       }     }     return 0;   }   