fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const ll N=5e5+5;
  5. ll n,m,st[4*N];
  6. void update(ll id,ll l,ll r,ll pos,ll val)
  7. {
  8. if(r<pos||l>pos)return ;
  9. if(l==r)
  10. {
  11. st[id]+=val;
  12. return ;
  13. }
  14. ll mid=(l+r)/2;
  15. update(id*2,l,mid,pos,val);
  16. update(id*2+1,mid+1,r,pos,val);
  17. st[id]=max(st[id*2],st[id*2+1]);
  18. }
  19. ll get(ll id,ll l,ll r,ll u,ll v)
  20. {
  21. if(u>r||v<l)return -1e18;
  22. if(l>=u&&r<=v)return st[id];
  23. ll mid=(l+r)/2;
  24. return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
  25. }
  26. int main()
  27. {
  28. ios_base::sync_with_stdio(0);
  29. cin.tie(0);cout.tie(0);
  30. cin>>n>>m;
  31. while(m--)
  32. {
  33. ll k,x,y;
  34. cin>>k>>x>>y;
  35. if(k==0)
  36. {
  37. update(1,1,n,x,y);
  38. }
  39. else
  40. {
  41. cout<<get(1,1,n,x,y)<<"\n";
  42. }
  43. }
  44. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty