fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int const N=1<<25;
  4. int const poc=(1<<24)-1;
  5. long long a,b,c,tab[N],w;
  6.  
  7. long long Read(int v)
  8. {
  9. w=0;
  10. while(v>0)
  11. {
  12. w+=tab[v];
  13. v/=2;
  14. }
  15. return w;
  16. }
  17.  
  18. void Update(int v, int p, int k)
  19. {
  20. if(k<a||p>b) return;
  21. if(p>=a&&k<=b) tab[v]+=c; //cout<<v<<' '<<tab[v]<<"\n";}
  22. else {
  23. Update(2*v,p,(p+k)/2);
  24. Update(2*v+1,(p+k)/2+1,k);
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0); cout.tie(0);
  32. int n,k,q;
  33. char x;
  34. cin>>n>>k>>q;
  35. for(int i=0;i<n+q;i++)
  36. {
  37. if(i<n)
  38. {
  39. cin>>a>>b>>c;
  40. a+=poc;
  41. b+=poc;
  42. Update(1,poc+1,N-1);
  43. }
  44. else
  45. {
  46. cin>>a;
  47. a+=poc;
  48. cout<<Read(a)<<"\n";
  49. }
  50. }
  51. }
Success #stdin #stdout 0.01s 9744KB
stdin
3 4 3
1 4 3
1 2 2
2 3 1
1
2
4
stdout
5
6
3