sacgajcvs

Untitled

Dec 17th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33.  
  34. /* For Debugging */
  35. #define DEBUG cerr<<"/n>>>I'm Here<<</n"<<endl;
  36. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  37. #define what_is(x) cerr << #x << " is " << x << endl;
  38.  
  39. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  40. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  41. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  42. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  43. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  44. using namespace __gnu_pbds;
  45. using namespace std;
  46. #define PI 3.141592653589793
  47. #define N 200005
  48. vi a(N),seg(4*N);
  49. void build(ll cur,ll st,ll end)
  50. {
  51. if(st==end)
  52. {
  53. seg[cur]=a[st];
  54. return;
  55. }
  56. ll mid=(st+end)>>1;
  57. build(2*cur,st,mid);
  58. build(2*cur+1,mid+1,end);
  59. seg[cur]=seg[2*cur]+seg[2*cur+1]; /* 1-change here */
  60. }
  61. ll query(ll cur,ll st,ll end,ll l,ll r)
  62. {
  63. if(l<=st&&r>=end)
  64. return seg[cur];
  65. if(r<st||l>end)
  66. return 0; /* 2-change here */
  67. ll mid=(st+end)>>1;
  68. ll ans1=query(2*cur,st,mid,l,r);
  69. ll ans2=query(2*cur+1,mid+1,end,l,r);
  70. return (ans1+ans2); /* 3-change here */
  71. }
  72. void update(ll cur,ll st,ll end,ll pos,ll upd)
  73. {
  74. if(st==end)
  75. {
  76. a[pos]+=upd; /* 4-change here */
  77. seg[cur]=max(a[pos],0LL); /* 5-change here */
  78. return;
  79. }
  80. ll mid=(st+end)>>1;
  81. if(st<=pos&&pos<=mid)
  82. update(2*cur,st,mid,pos,upd);
  83. else
  84. update(2*cur+1,mid+1,end,pos,upd);
  85. seg[cur]=seg[2*cur]+seg[2*cur+1]; /* 6-change here */
  86. }
  87. void solve()
  88. {
  89. ll n;
  90. cin>>n;
  91. rep(i,1,n+1)
  92. {
  93. cin>>a[i];
  94. }
  95. build(1,1,n);
  96. ll q;
  97. cin>>q;
  98. map<pii,ll>ma;
  99. rep(i,0,q)
  100. {
  101. ll s,t,u;
  102. cin>>s>>t>>u;
  103. if(ma[{s,t}])
  104. {
  105. update(1,1,n,ma[{s,t}],1);
  106. }
  107. ma[{s,t}]=u;
  108. if(u!=0)
  109. update(1,1,n,ma[{s,t}],-1);
  110. cout<<query(1,1,n,1,n)<<endl;
  111. }
  112. return;
  113. }
  114. int main()
  115. {
  116. FAST
  117. int TESTS=1;
  118. // cin>>TESTS;
  119. while(TESTS--)
  120. {
  121. solve();
  122. }
  123. TIME
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment