fork download
  1. // ~~ icebear love attttt ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "icebearat"
  33.  
  34. const int MOD = 1e9 + 7;
  35. const int inf = 1e9 + 27092008;
  36. const ll INF = 1e18 + 27092008;
  37. const int N = 2e5 + 5;
  38. int n, q;
  39. int a[N], fen[N], power2[N];
  40.  
  41. void update(int x, int val) {
  42. for(; x <= n; x += x & -x) fen[x] += val;
  43. }
  44.  
  45. int getSum(int x) {
  46. int ans = 0;
  47. for(; x; x -= x & -x) ans += fen[x];
  48. return ans;
  49. }
  50.  
  51. int get(int l, int r) {
  52. return getSum(r) - getSum(l - 1);
  53. }
  54.  
  55. void init(void) {
  56. cin >> n >> q;
  57. FOR(i, 1, n) {
  58. cin >> a[i];
  59. if (a[i] % 2 == 0) update(i, +1);
  60. }
  61. }
  62.  
  63. void process(void) {
  64. power2[0] = 1;
  65. FOR(i, 1, n) power2[i] = 1LL * power2[i - 1] * 2 % MOD;
  66. int type, l, r;
  67. while(q--) {
  68. cin >> type >> l >> r;
  69. if (type == 1) {
  70. if (a[l] % 2 == 0) update(l, -1);
  71. a[l] = r;
  72. if (a[l] % 2 == 0) update(l, +1);
  73. } else {
  74. int even = get(l, r), odd = (r - l + 1) - even;
  75. int ans = 0;
  76. ans = (ans + (power2[even] - 1 + MOD) % MOD) % MOD;
  77. if (odd > 0) {
  78. ans = (ans + (power2[odd - 1] - 1 + MOD) % MOD) % MOD;
  79. ans = (ans + 1LL * (power2[even] - 1 + MOD) % MOD * (power2[odd - 1] - 1 + MOD) % MOD) % MOD;
  80. }
  81. cout << ans << '\n';
  82. }
  83. }
  84. }
  85.  
  86. int main() {
  87. ios_base::sync_with_stdio(0);
  88. cin.tie(0); cout.tie(0);
  89. if (fopen(task".inp", "r")) {
  90. freopen(task".inp", "r", stdin);
  91. freopen(task".out", "w", stdout);
  92. }
  93. int tc = 1;
  94. // cin >> tc;
  95. while(tc--) {
  96. init();
  97. process();
  98. }
  99. return 0;
  100. }
  101.  
  102.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty