fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll ;
  6.  
  7.  
  8. const ll MAX = 100009 ;
  9. ll tree[5*MAX] = {0};
  10. ll lazy[5*MAX] = {0};
  11.  
  12. void update(ll node , ll left , ll right , ll from , ll to , ll val)
  13. {
  14. if(lazy[node] != 0)
  15. {
  16. tree[node] += (right-left+1) * lazy[node];
  17. if (left != right)
  18. {
  19. lazy[2*node] += lazy[node];
  20. lazy[2*node+1] += lazy[node];
  21. }
  22. lazy[node] = 0;
  23. }
  24.  
  25. if (left > right || left > to || right < from)
  26. return ;
  27.  
  28. if(left >= from && right <= to)
  29. {
  30. tree[node] += (right-left+1)*val;
  31.  
  32. if(left != right)
  33. {
  34. lazy[2*node] += val ;
  35. lazy[2*node+1] += val ;
  36. }
  37. return ;
  38. }
  39. ll mid = (left + right) >> 1 ;
  40. update(node*2 , left , mid , from , to , val);
  41. update(2*node+1,mid+1,right,from,to,val);
  42. tree[node] = tree[2*node] + tree[2*node+1];
  43. }
  44.  
  45. ll query(ll node , ll left, ll right, ll from, ll to)
  46. {
  47. if(lazy[node] != 0)
  48. {
  49. tree[node] += (right - left + 1) * lazy[node];
  50. if(left != right)
  51. {
  52. lazy[2*node] += lazy[node];
  53. lazy[2*node+1] += lazy[node];
  54. }
  55. lazy[node] = 0 ;
  56. }
  57. if(left > right || left > to || right < from)
  58. return 0 ;
  59.  
  60. if(left >= from && right <= to)
  61. return tree[node];
  62.  
  63. ll mid = (left + right) >> 1 ;
  64. return query(2*node , left , mid , from , to) +
  65. query(2*node+1,mid+1,right,from,to);
  66. }
  67.  
  68. int main()
  69. {
  70. ll t ;
  71. scanf("%lld" , &t);
  72. ll cnt = 0;
  73. while(t--)
  74. {
  75. for(int i = 0 ; i < 5*MAX ; ++i)
  76. lazy[i] = tree[i] = 0 ;
  77. ll n , q ;
  78. scanf("%lld %lld" , &n , &q);
  79. ll arr[100005] = {0};
  80. printf("Scenario #%lld:\n",++cnt);
  81. while(q--)
  82. {
  83. char s[15];
  84. ll x ,y ;
  85. scanf("%s",&s);
  86. scanf("%lld %lld" , &x , &y);
  87. if(x > y)
  88. printf("0\n");
  89. else if(s[0] == 'a')
  90. printf("%lld\n",query(1,0,n-1,x-1,y-1));
  91. else
  92. {
  93. update(1,0,n-1,x-1,y-1,1);
  94. printf("OK\n");
  95. }
  96. }
  97. }
  98. return 0 ;
  99. }
  100.  
Runtime error #stdin #stdout 0.01s 10652KB
stdin
Standard input is empty
stdout
Standard output is empty