Pagini recente » Monitorul de evaluare | Borderou de evaluare (job #3110301) | Cod sursa (job #3335457) | Monitorul de evaluare | Cod sursa (job #3030442)
#include<bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int N = 1e5 + 5;
int n, p, q, task, x, y, aint[4 * N];
void init(), update(int, int);
int query(int, int, int);
int main()
{
init();
for (; q; q--){
f >> task >> x >> y;
if (task) update(x, y);
else g << query(1, 1, p + 1) << '\n';
}
return 0;
}
void init(){
f >> n >> q;
p = 1; while (p <= n) p <<= 1; p--;
for (int i = 1; i <= n; i++) f >> aint[i + p];
for (int i = p; i; i--)
aint[i] = max(aint[i<<1], aint[i<<1|1]);
}
void update(int poz, int val){
poz += p; aint[poz] = val; poz >>= 1;
while (poz){
aint[poz] = max(aint[poz<<1], aint[poz<<1|1]);
poz >>= 1;
}
}
int query(int nod, int l, int r){
if (y < l || r < x) return 0;
if (x <= l && r <= y) return aint[nod];
int mi = (l + r) / 2;
return max(query(nod<<1, l, mi), query(nod<<1|1, mi + 1, r));
}