#include <bits/stdc++.h>
#define Intro ios::sync_with_stdio(0), cin.tie(0)
#define ll long long
using namespace std;
ifstream fin("arbint.in");
ofstream fout ("arbint.out");
int const N = 3e5 + 5;
int segment_tree[N], maximum;
void update(int node, int left, int right, int value, int pos) {
if (left == right) {
segment_tree[node] = value;
return;
}
int mid = (left + right) / 2;
if (pos <= mid) {
update(2 * node, left, mid, value, pos);
} else {
update(2 * node + 1, mid + 1, right, value, pos);
}
segment_tree[node] = max(segment_tree[2 * node], segment_tree[2 * node + 1]);
}
void query(int node, int left, int right, int segment_start, int segment_finish) {
if (segment_start <= left and right <= segment_finish) {
maximum = max(maximum, segment_tree[node]);
return;
}
int mid = (left + right) / 2;
if (segment_start <= mid) {
query(2 * node, left, mid, segment_start, segment_finish);
}
if (segment_finish > mid) {
query(2 * node + 1, mid + 1, right, segment_start, segment_finish);
}
}
int main() {
int elements, queries;
fin >> elements >> queries;
for (int i = 1; i <= elements; ++i) {
int value; fin >> value;
update(1, 1, elements, value, i);
}
for (int i = 1; i <= queries; ++i) {
int code, a, b;
fin >> code >> a >> b;
if (code == 0) {
maximum = -1;
query(1, 1, elements, a, b);
fout << maximum << '\n';
} else {
update(1, 1, elements, b, a);
}
}
//read the stuff below
return 0;
}
/* Plan
- read the statement carefully
- write stuff down (observations and ideas)
- consider the methods
- revise the solution before implementing it
- int overflow
- edge cases
- make the implementation clearly
*/