Pagini recente » Cod sursa (job #11776) | Cod sursa (job #2140954) | Cod sursa (job #1016248) | Cod sursa (job #30858) | Cod sursa (job #1626290)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int N_MAX = 1e5+1;
#define LC (nod << 1)
#define RC ((nod << 1) + 1)
int n, m;
int v[(N_MAX << 4)];
int st, dr, maxim, val;
void query(int a, int b, int nod) {
if(st <= a && b <= dr) {
maxim = max(maxim, v[nod]);
return;
}
int mij = (a + b) >> 1;
if(st <= mij)
query(a, mij, LC);
if(mij < dr)
query(mij + 1, b, RC);
}
void update(int a, int b, int nod) {
if(a == b) {
v[nod] = val;
return;
}
int mij = (a + b) >> 1;
if(st <= mij)
update(a, mij, LC);
else
update(mij+1, b, RC);
v[nod] = max(v[LC], v[RC]);
}
int main() {
fin >> n >> m;
for(int i = 1; i <= n; ++i) {
fin >> val;
st = dr = i;
update(1, n, 1);
}
int t, a, b;
while(m--) {
fin >> t >> a >> b;
if(!t) {
st = a; dr = b;
maxim = -1;
query(1, n, 1);
fout << maxim << "\n";
} else {
st = dr = a;
val = b;
update(1, n, 1);
}
}
}