Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<ext/pb_ds/assoc_container.hpp>
- #include<ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>_Bohemian;
- int arr[200005],b[200005];
- int main ()
- {
- int n,m;
- _Bohemian st;
- cin>>n;
- for (int i=1; i<=n; i++)
- {
- cin>>arr[i];
- st.insert(i);
- }
- cin>>m;
- for (int i=0; i<m; i++)
- {
- int chk,que;
- cin>>chk;
- if (chk==2)
- {
- cin>>que;
- cout<<b[que]<<endl;
- }
- else
- {
- int p,q;
- cin>>p>>q;
- while(q>0)
- {
- auto it=st.lower_bound(p);
- if (it==st.end())
- break;
- auto x =*it;
- if (q<arr[x]-b[x])
- {
- b[x]+=q;
- q=0;
- }
- else
- {
- q-=(arr[x]-b[x]);
- b[x]=arr[x];
- st.erase(it);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment