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, a[N];
  39. array<int, 3> Q[N];
  40.  
  41. class FenwickTree {
  42. private:
  43. int n;
  44. vector<int> fen;
  45.  
  46. int get(int x) {
  47. int ans = 0;
  48. for(; x; x -= x & -x) ans += fen[x];
  49. return ans;
  50. }
  51. public:
  52. FenwickTree(int _n = 0): n(_n), fen(_n + 5, 0) {}
  53.  
  54. void update(int x, int val) {
  55. for(; x <= n; x += x & -x) fen[x] += val;
  56. }
  57.  
  58. int query(int l, int r) {
  59. assert(l > 0);
  60. return get(r) - get(l - 1);
  61. }
  62. } BIT;
  63.  
  64. struct SegmentTree {
  65. int n;
  66. vector<int> node;
  67. SegmentTree(int _n = 0): n(_n), node((_n << 2) + 5, 0) {}
  68.  
  69. void update(int pos, int value) {
  70. int id = 1, l = 1, r = n;
  71. while(l < r) {
  72. int mid = (l + r) >> 1;
  73. if (pos > mid) id = (id << 1 | 1), l = mid + 1;
  74. else id = (id << 1), r = mid;
  75. }
  76. node[id] = value;
  77. while(id) {
  78. id >>= 1;
  79. node[id] = max(node[id << 1], node[id << 1 | 1]);
  80. }
  81. }
  82.  
  83. int getMax(int id, int l, int r, int u, int v) {
  84. if (l > v || r < u) return -inf;
  85. if (u <= l && r <= v) return node[id];
  86. int mid = (l + r) >> 1;
  87. return max(getMax(id << 1, l, mid, u, v), getMax(id << 1 | 1, mid + 1, r, u, v));
  88. }
  89.  
  90. int getMax(int u, int v) {
  91. return getMax(1, 1, n, u, v);
  92. }
  93. } IT;
  94.  
  95. int realPos(int x) {
  96. int last = 1;
  97. while(BIT.query(last, x)) {
  98. int tmp = x;
  99. x += BIT.query(last, x);
  100. last = tmp + 1;
  101. }
  102. return x;
  103. }
  104.  
  105. void init(void) {
  106. cin >> n >> q;
  107. FOR(i, 1, n) cin >> a[i];
  108. FOR(i, 1, q) cin >> Q[i][0] >> Q[i][1] >> Q[i][2];
  109. }
  110.  
  111. void process(void) {
  112. BIT = FenwickTree(n + q);
  113. IT = SegmentTree(n + q);
  114. FORR(i, q, 1) {
  115. Q[i][1] = realPos(Q[i][1]);
  116. if (Q[i][0] == 1) {
  117. BIT.update(Q[i][1], +1);
  118. } else Q[i][2] = realPos(Q[i][2]);
  119. }
  120.  
  121. FOR(i, 1, n) IT.update(realPos(i), a[i]);
  122. FOR(i, 1, q) {
  123. if (Q[i][0] == 1) IT.update(Q[i][1], Q[i][2]);
  124. else cout << IT.getMax(Q[i][1], Q[i][2]) << '\n';
  125. }
  126. }
  127.  
  128. int main() {
  129. ios_base::sync_with_stdio(0);
  130. cin.tie(0); cout.tie(0);
  131. if (fopen(task".inp", "r")) {
  132. freopen(task".inp", "r", stdin);
  133. freopen(task".out", "w", stdout);
  134. }
  135. int tc = 1;
  136. // cin >> tc;
  137. while(tc--) {
  138. init();
  139. process();
  140. }
  141. return 0;
  142. }
  143.  
  144.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty