fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. long int array[1000001] = {0};
  4. void increment(int value,int idx,int size)
  5. {
  6. long int lenBIT = size + 1;
  7. long int i = idx + 1;
  8. while (i < lenBIT)
  9. {
  10. array[i] += value;
  11. i += (i & -i);
  12. }
  13. }
  14. long int query(long int idx)
  15. {
  16. long int i = idx + 1;
  17. long int sum = 0;
  18. while (i)
  19. {
  20. sum += array[i];
  21. i -= (i & -i);
  22. }
  23. return sum;
  24. }
  25. int main (void)
  26. {
  27. int n,q,i,temp;
  28. scanf ("%d %d",&n,&q);
  29. for (i = 0; i < n; ++i)
  30. {
  31. scanf ("%d",&temp);
  32. increment(temp, i, n);
  33. }
  34. for (q; q > 0; --q)
  35. {
  36. char c[10] = {0};
  37. scanf ("%c",c);
  38. if ((c[0] == 'G'))
  39. increment(c[4]-48, c[2]-48, n);
  40. else if ((c[0] == 'T'))
  41. increment(-(c[4]-48), c[2]-48, n);
  42. else if (c[0] == 'S')
  43. printf ("%ld\n", (query(c[4]-48) - query(c[2]-48-1)));
  44. }
  45. return 0;
  46. }
Runtime error #stdin #stdout 0s 6196KB
stdin
5 3
1000 1002 1003 1004 1005
S 0 2
G 0 3
S 0 2
stdout
Standard output is empty