#pragma once
#include<iostream>
#include<fstream>
using namespace std;
#define NN 100001
int arboreInterval[NN], elemMax;
using namespace std;
int valMax(int a, int b) {
if (a > b)
return a;
return b;
}
void aPrimesteB(int nod, int st, int dr, int pozA, int valB) { //caz particular, se cauta valoare, nu interval
if (st == dr) {
arboreInterval[nod] = valB;
return;
}
int mij = st + (dr - st) / 2;
if (2 * nod > NN)
return;
if (pozA <= mij)
aPrimesteB(2 * nod, st, mij, pozA, valB);
if (pozA > mij)
aPrimesteB(2 * nod + 1, mij + 1, dr, pozA, valB);
arboreInterval[nod] = valMax(arboreInterval[2 * nod], arboreInterval[2 * nod + 1]);
}
void maximInterval(int nod, int st, int dr, int a, int b) { //st si dr de la arbore, a si b capetele intervalului de vazut
if (a <= st && b >= dr) {
if (arboreInterval[nod] > elemMax)
elemMax = arboreInterval[nod];
return;
}
if (2 * nod > NN) {
return;
}
int mij = st + (dr - st) / 2;
if (a <= mij)
maximInterval(2 * nod, st, mij, a, b);
if (b > mij)
maximInterval(2 * nod + 1, mij + 1, dr, a, b);
}
void problema() {
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int N, M, val;
fin >> N >> M;
for (int i = 1; i <= N; i++) {
fin >> val;
aPrimesteB(1, 1, N, i, val);
}
for (int i = 1; i <= M; i++) {
int optiune, a, b;
fin >> optiune;
fin >> a >> b;
if (optiune == 0) {
elemMax = -1;
maximInterval(1, 1, N, a, b);
fout << elemMax << "\n";
}
else {
aPrimesteB(1, 1, N, a, b);
}
}
}