fork download
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ifstream cin("rsq.in");
  8. ofstream cout("rsq.out");
  9. ios::sync_with_stdio(false);
  10. unsigned int n, m, i;
  11. long long sum = 0, sum_k;
  12. int *a, x, y;
  13. bool t;
  14. cin >> n >> m; n++;
  15. a = new int[n];
  16. for (i = 1; i < n; i++)
  17. {
  18. cin >> a[i];
  19. sum += a[i];
  20. }
  21. const unsigned int ndiv2 = n/2;
  22. while (m--)
  23. {
  24. cin >> t >> x;
  25. if (t)
  26. {
  27. sum -= a[x];
  28. cin >> a[x];
  29. sum += a[x];
  30. }
  31. else
  32. {
  33. cin >> y;
  34. y++;
  35. if (y - x > ndiv2)
  36. {
  37. sum_k = sum;
  38. for (i = 1; i < x; i++)
  39. {
  40. sum_k -= a[i];
  41. }
  42. for (i = y; i < n; i++)
  43. {
  44. sum_k -= a[i];
  45. }
  46. }
  47. else
  48. {
  49. sum_k = 0;
  50. for (; x < y; x++)
  51. {
  52. sum_k += a[x];
  53. }
  54. }
  55. cout << sum_k << endl;
  56. }
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0s 16064KB
stdin
5 3
1 2 3 4 5
0 1 5
1 1 -14
0 1 5
stdout
15
0