fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <set>
  6. #include <vector>
  7. #include <bits/stdc++.h>
  8. #include <numeric>
  9. using namespace std;
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. using namespace __gnu_pbds;
  12. template <class T>
  13. using orderStaticTree =
  14. tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  15.  
  16. //
  17. #include <bits/stdc++.h>
  18. using namespace std;
  19.  
  20. // Import indexed sets
  21. #include <ext/pb_ds/assoc_container.hpp>
  22. using namespace __gnu_pbds;
  23. template <class T>
  24. using Tree =
  25. tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  26.  
  27. #define ll long long
  28.  
  29. #define saleh \
  30.   ios_base::sync_with_stdio(false); \
  31.   cin.tie(nullptr);
  32.  
  33. const int MX = 4e5 + 5;
  34. ll BIT[MX];
  35.  
  36. void ad(int x, int val)
  37. {
  38. for (; x < 10; x += (x & (-x))){
  39. cout<<x<<endl;
  40. BIT[x] += val;
  41. }
  42.  
  43. }
  44.  
  45. ll query(int x)
  46. {
  47. ll ret = 0;
  48. for (; x; x -= (x & (-x))){
  49. // cout<<"x "<<x<<endl;
  50. ret += BIT[x];
  51. }
  52.  
  53.  
  54. return ret;
  55. }
  56.  
  57. int main()
  58. {
  59. // using BIT , range update , point query
  60. int n, q;
  61. cin >> n >> q;
  62.  
  63. for (int i = 0; i < n; i++)
  64. {
  65. int x;
  66. cin >> x;
  67. cout<<" x " <<x<<endl;
  68. ad(i + 1, x);
  69.  
  70. cout<<"________________"<<endl;
  71. ad(i + 2, -x);
  72. cout<<"________________2"<<endl;
  73. }
  74. for(int i =1;i<=n;i++)cout<<BIT[i]<<" ";
  75. cout<<endl;
  76. while (q--)
  77. {
  78. int op;
  79. cin >> op;
  80. if (op == 1)
  81. {
  82. int l, r, u;
  83. cin >> l >> r >> u;
  84. // ad(l, u);
  85. // ad(r + 1, -u);
  86. }
  87. else
  88. {
  89. int ind;
  90. cin >> ind;
  91. // cout<<" ans ";
  92. cout << query(ind) << endl;
  93. }
  94. }
  95.  
  96. return 0;
  97. }
  98.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
 x -338552408
1
2
4
8
________________
2
4
8
________________2
-338552408