fork download
  1. #pragma GCC optimize("O3,unroll-loops")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define fi first
  5. #define se second
  6. #define ll long long
  7. #define ull unsigned ll
  8. #define sz(x) (int)(x).size()
  9. #define all(x) (x).begin(),(x).end()
  10. #define f0(i,n) for(int i=0;i<n;i++)
  11. #define f1(i,n) for(int i=1;i<=n;i++)
  12. #define fz(i,a,n,z) for(int i=a;i<n;i+=z)
  13. #define rep(i,a,n,z) for(int i=a;i>n;i-=z)
  14. #define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  15. #define file(name) freopen(name".inp","r",stdin);freopen(name".out","w",stdout);
  16. const int N = 1e6 + 5;
  17. ll max_uocLe(ll n) {
  18. if (n % 2 == 1) return n;
  19. ll res = 1;
  20. for (ll i = 2; i <= sqrt(n); ++i) {
  21. if (n % i == 0) {
  22. if (i % 2 == 1) {
  23. res = max(res, i);
  24. }
  25. if ((n / i) % 2 == 1) {
  26. res = max(res, n / i);
  27. }
  28. }
  29. }
  30. return res;
  31. }
  32. ll pre[N];
  33. ll to = 0, z[200001], n, k, i, m, a[200001], x[200001], y[200001], d[200001] = {};
  34. int main() {
  35. faster
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(0);
  38. cout.tie(0);
  39. cin >> n >> m;
  40. for (i = 1; i <= n; i++) {cin >> a[i]; pre[i] = pre[i - 1] + a[i] + a[max_uocLe(i)];}
  41. for (i = 1; i <= n; i++)
  42. {
  43. k = i;
  44. while (k % 2 == 0) k /= 2;
  45. d[i] = k;
  46.  
  47.  
  48. }
  49. bool check = true;
  50. for (i = 1; i <= m; ++i) {
  51. cin >> x[i] >> y[i] >> z[i];
  52. if (x[i] == 1) {
  53. check = false;
  54. }
  55. }
  56. if (check == false) {
  57. for (ll it = 1; it <= m; ++it)
  58. {
  59. if (x[it] == 1)
  60. {
  61. swap(a[y[it]], z[it]);
  62. }
  63. else
  64. {
  65. to = 0;
  66. for (i = y[it]; i <= z[it]; i++)
  67. {
  68. to += a[i] + a[d[i]];
  69. }
  70. cout << to << "\n";
  71. }
  72. }
  73. }
  74. else {
  75. for (ll it = 1; it <= m; ++it) {
  76. cout << pre[z[it]] - pre[y[it] - 1] << "\n";
  77. }
  78. }
  79.  
  80. }
  81.  
  82. /*-----------------------END-----------------------*/
  83.  
  84.  
  85.  
  86.  
  87.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty