fork download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #define gc getchar
  4. typedef long long ll;
  5. ll maxi;
  6. ll array[1000003];
  7. void bt1(ll index,ll value)
  8. {
  9. while(index<=maxi)
  10. {
  11. array[index]=array[index]+value;
  12. index=index+(index & -index);
  13. }
  14. }
  15. ll qt(ll a)
  16. {
  17. ll sum=0;
  18. while(a>0)
  19. {
  20. sum=sum+array[a];
  21. a=a-(a & -a);
  22. }
  23. return sum;
  24. }
  25. int main()
  26. {
  27. using namespace std;
  28. ll n,m,c,i,x,y,z,a,ans;
  29. string s;
  30. maxi=n+1;
  31. for(i=0;i<1000003;i++)
  32. array[i]=0;
  33. for(i=1;i<=n;i++)
  34. bt1(i,c);
  35. if(m>0)
  36. while(m--)
  37. {
  38. cin>> s;
  39.  
  40. if(s[0]=='S')
  41. {
  42. bt1(x,z);
  43. bt1(y+1,-z);
  44. }
  45. else
  46. {
  47. ans=qt(a);
  48. printf("%lld\n",ans);
  49. }
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 11272KB
stdin
Standard input is empty
stdout
Standard output is empty