// ~~ icebear love attttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, q, a[N];
array<int, 3> Q[N];
class FenwickTree {
private:
int n;
vector<int> fen;
int get(int x) {
int ans = 0;
for(; x; x -= x & -x) ans += fen[x];
return ans;
}
public:
FenwickTree(int _n = 0): n(_n), fen(_n + 5, 0) {}
void update(int x, int val) {
for(; x <= n; x += x & -x) fen[x] += val;
}
int query(int l, int r) {
assert(l > 0);
return get(r) - get(l - 1);
}
} BIT;
struct SegmentTree {
int n;
vector<int> node;
SegmentTree(int _n = 0): n(_n), node((_n << 2) + 5, 0) {}
void update(int pos, int value) {
int id = 1, l = 1, r = n;
while(l < r) {
int mid = (l + r) >> 1;
if (pos > mid) id = (id << 1 | 1), l = mid + 1;
else id = (id << 1), r = mid;
}
node[id] = value;
while(id) {
id >>= 1;
node[id] = max(node[id << 1], node[id << 1 | 1]);
}
}
int getMax(int id, int l, int r, int u, int v) {
if (l > v || r < u) return -inf;
if (u <= l && r <= v) return node[id];
int mid = (l + r) >> 1;
return max(getMax(id << 1, l, mid, u, v), getMax(id << 1 | 1, mid + 1, r, u, v));
}
int getMax(int u, int v) {
return getMax(1, 1, n, u, v);
}
} IT;
int realPos(int x) {
int last = 1;
while(BIT.query(last, x)) {
int tmp = x;
x += BIT.query(last, x);
last = tmp + 1;
}
return x;
}
void init(void) {
cin >> n >> q;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, q) cin >> Q[i][0] >> Q[i][1] >> Q[i][2];
}
void process(void) {
BIT = FenwickTree(n + q);
IT = SegmentTree(n + q);
FORR(i, q, 1) {
Q[i][1] = realPos(Q[i][1]);
if (Q[i][0] == 1) {
BIT.update(Q[i][1], +1);
} else Q[i][2] = realPos(Q[i][2]);
}
FOR(i, 1, n) IT.update(realPos(i), a[i]);
FOR(i, 1, q) {
if (Q[i][0] == 1) IT.update(Q[i][1], Q[i][2]);
else cout << IT.getMax(Q[i][1], Q[i][2]) << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dCB+fgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IGlpOwp0eXBlZGVmIHBhaXI8aW50LCBpaT4gaWlpOwoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWluaW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhID4gYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCnRlbXBsYXRlPGNsYXNzIFQ+CiAgICBib29sIG1heGltaXplKFQgJmEsIGNvbnN0IFQgJmIpIHsKICAgICAgICBpZiAoYSA8IGIpIHJldHVybiBhID0gYiwgdHJ1ZTsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CgojZGVmaW5lIEZPUihpLGEsYikgZm9yKGludCBpPShhKTsgaTw9KGIpOyArK2kpCiNkZWZpbmUgRk9SUihpLGEsYikgZm9yKGludCBpPShhKTsgaT49KGIpOyAtLWkpCiNkZWZpbmUgUkVQKGksIG4pIGZvcihpbnQgaT0wOyBpPChuKTsgKytpKQojZGVmaW5lIFJFRChpLCBuKSBmb3IoaW50IGk9KG4pLTE7IGk+PTA7IC0taSkKI2RlZmluZSBNQVNLKGkpICgxTEwgPDwgKGkpKQojZGVmaW5lIEJJVChTLCBpKSAoKChTKSA+PiAoaSkpICYgMSkKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCkKI2RlZmluZSB0YXNrICJpY2ViZWFyYXQiCgpjb25zdCBpbnQgTU9EID0gMWU5ICsgNzsKY29uc3QgaW50IGluZiA9IDFlOSArIDI3MDkyMDA4Owpjb25zdCBsbCBJTkYgPSAxZTE4ICsgMjcwOTIwMDg7CmNvbnN0IGludCBOID0gMmU1ICsgNTsKaW50IG4sIHEsIGFbTl07CmFycmF5PGludCwgMz4gUVtOXTsKCmNsYXNzIEZlbndpY2tUcmVlIHsKcHJpdmF0ZToKICAgIGludCBuOwogICAgdmVjdG9yPGludD4gZmVuOwoKICAgIGludCBnZXQoaW50IHgpIHsKICAgICAgICBpbnQgYW5zID0gMDsKICAgICAgICBmb3IoOyB4OyB4IC09IHggJiAteCkgYW5zICs9IGZlblt4XTsKICAgICAgICByZXR1cm4gYW5zOwogICAgfQpwdWJsaWM6CiAgICBGZW53aWNrVHJlZShpbnQgX24gPSAwKTogbihfbiksIGZlbihfbiArIDUsIDApIHt9CgogICAgdm9pZCB1cGRhdGUoaW50IHgsIGludCB2YWwpIHsKICAgICAgICBmb3IoOyB4IDw9IG47IHggKz0geCAmIC14KSBmZW5beF0gKz0gdmFsOwogICAgfQoKICAgIGludCBxdWVyeShpbnQgbCwgaW50IHIpIHsKICAgICAgICBhc3NlcnQobCA+IDApOwogICAgICAgIHJldHVybiBnZXQocikgLSBnZXQobCAtIDEpOwogICAgfQp9IEJJVDsKCnN0cnVjdCBTZWdtZW50VHJlZSB7CiAgICBpbnQgbjsKICAgIHZlY3RvcjxpbnQ+IG5vZGU7CiAgICBTZWdtZW50VHJlZShpbnQgX24gPSAwKTogbihfbiksIG5vZGUoKF9uIDw8IDIpICsgNSwgMCkge30KCiAgICB2b2lkIHVwZGF0ZShpbnQgcG9zLCBpbnQgdmFsdWUpIHsKICAgICAgICBpbnQgaWQgPSAxLCBsID0gMSwgciA9IG47CiAgICAgICAgd2hpbGUobCA8IHIpIHsKICAgICAgICAgICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgICAgICAgICAgaWYgKHBvcyA+IG1pZCkgaWQgPSAoaWQgPDwgMSB8IDEpLCBsID0gbWlkICsgMTsKICAgICAgICAgICAgZWxzZSBpZCA9IChpZCA8PCAxKSwgciA9IG1pZDsKICAgICAgICB9CiAgICAgICAgbm9kZVtpZF0gPSB2YWx1ZTsKICAgICAgICB3aGlsZShpZCkgewogICAgICAgICAgICBpZCA+Pj0gMTsKICAgICAgICAgICAgbm9kZVtpZF0gPSBtYXgobm9kZVtpZCA8PCAxXSwgbm9kZVtpZCA8PCAxIHwgMV0pOwogICAgICAgIH0KICAgIH0KCiAgICBpbnQgZ2V0TWF4KGludCBpZCwgaW50IGwsIGludCByLCBpbnQgdSwgaW50IHYpIHsKICAgICAgICBpZiAobCA+IHYgfHwgciA8IHUpIHJldHVybiAtaW5mOwogICAgICAgIGlmICh1IDw9IGwgJiYgciA8PSB2KSByZXR1cm4gbm9kZVtpZF07CiAgICAgICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgICAgICByZXR1cm4gbWF4KGdldE1heChpZCA8PCAxLCBsLCBtaWQsIHUsIHYpLCBnZXRNYXgoaWQgPDwgMS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