Pagini recente » Cod sursa (job #1408861) | Cod sursa (job #1224896) | Cod sursa (job #2633871) | Cod sursa (job #2419911) | Cod sursa (job #3274729)
//100 Puncte
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
int v[100005], n, m, aint[400005], a, b ;
void update (int pos, int left, int right)
{
if (left==right) {
aint[pos]=b;
return;
}
int mid = (left+right)/2;
if (a<=mid) {
update(2*pos, left, mid);
}
else {
update(2*pos+1, mid+1, right);
}
aint[pos] = max(aint[2*pos], aint[2*pos+1]);
}
int querry (int pos, int left, int right) {
int max_1=-1, max_2=-1;
int mid = (left+right)/2;
if (a<=left&&right<=b) {
return aint[pos];
}
if (a<=mid) max_1 = querry(2*pos, left, mid);
if (b>mid) max_2 = querry(2*pos+1, mid+1, right);
return max(max_1, max_2);
}
int main()
{
fin.tie(0); fin.sync_with_stdio(false);
fin>>n>>m;
for (int i=1; i<=n; i++) {
a=i; fin>>b;
update(1, 1, n);
/*
Poate fi mai eficient sa facem o functie build care construieste
arborele dintr-un vector deja citit, coborand pe la toate frunzele
de-o data.
*/
}
for (int i=1; i<=m; i++) {
int op;
fin>>op>>a>>b;
if (op==0) {
fout<<querry(1, 1, n)<<'\n';
}
if (op==1) {
update(1, 1, n);
}
}
return 0;
}