fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long int arr[10000]={0};
  5.  
  6. long long int add(long int pos){
  7. // its for finding sum from 0 to pos
  8. long long int answer=0;
  9. for(int i=pos ; i>0 ; i-=(i&-i)){
  10. answer+=arr[i];
  11. }
  12. return answer;
  13. }
  14.  
  15. void update(long long int pos , long long int val , int n){
  16. for(int i=pos ; i<=n ; i+=(i&-i)){
  17. arr[i]+=val;
  18. }
  19. }
  20.  
  21. int main()
  22. {
  23. ios::sync_with_stdio(0);
  24. cin.tie(0); cout.tie(0);
  25. long long int n,m,c;
  26. std::cin >> n>>m>>c;
  27. while(m--){
  28. char s;std::cin >> s;
  29. if(s=='S'){
  30. long long int u,v,k;std::cin >> u>>v>>k;
  31. update(u,k,n);
  32. update(v+1,-k,n);
  33. }
  34. else{
  35. long int p;cin>>p;
  36. std::cout << add(p) << std::endl;
  37. }
  38.  
  39. }
  40.  
  41.  
  42. }
Success #stdin #stdout 0s 4696KB
stdin
7 5 0
Q 7
S 1 7 1
Q 3
S 1 3 1
Q 3
stdout
0
1
2