fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAX_N = 2e5 + 5;
  5. const int BLOCK_SIZE = 500;
  6.  
  7. int a[MAX_N];
  8. long long s[BLOCK_SIZE];
  9.  
  10. int main(){
  11. int n, q;
  12. cin >> n >> q;
  13.  
  14. for(int i = 0; i < n; i++){
  15. cin >> a[i];
  16. s[i / BLOCK_SIZE] += a[i];
  17. }
  18.  
  19. while(q--){
  20. int query;
  21. cin >> query;
  22.  
  23. if(query == 1){
  24. int id, val;
  25. cin >> id >> val;
  26. --id;
  27. s[id / BLOCK_SIZE] += val - a[id];
  28. a[id] = val;
  29. }
  30.  
  31. else{
  32. long long ans = 0;
  33. int l, r;
  34. cin >> l >> r;
  35. --l, --r;
  36.  
  37. int blockL = l / BLOCK_SIZE;
  38. int blockR = r / BLOCK_SIZE;
  39.  
  40. if(blockL == blockR){
  41. for(int i = l; i <= r; i++)
  42. ans += a[i];
  43. cout << ans << '\n';
  44. continue;
  45. }
  46.  
  47. for(int i = l, endP = (blockL + 1) * BLOCK_SIZE - 1; i <= endP; i++)
  48. ans += a[i];
  49. for(int i = blockL + 1; i <= blockR - 1; i++)
  50. ans += s[i];
  51. for(int i = blockR * BLOCK_SIZE; i <= r; i++)
  52. ans += a[i];
  53.  
  54. cout << ans << '\n';
  55. }
  56. }
  57.  
  58. return 0;
  59. }
Runtime error #stdin #stdout 0.01s 5356KB
stdin
Standard input is empty
stdout
Standard output is empty