Pagini recente » Cod sursa (job #2668316) | Cod sursa (job #1456195) | Cod sursa (job #2371608) | Cod sursa (job #2313365) | Cod sursa (job #2609965)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream r("arbint.in");
ofstream w("arbint.out");
int v[400000], maxim=0;
void update(int poz)
{
v[poz]=max(v[poz*2], v[poz*2+1]);
if(poz==1)
{
return;
}
else
{
update(poz/2);
}
}
void query(int st, int dr, int a, int b, int nod){
if(st==a && dr==b){
maxim=max(maxim, v[nod]);
}
else{
if(st<=(a+b)/2){
query(st, min(dr, (a+b)/2), a, (a+b)/2, nod*2);
}
if(dr>(a+b)/2){
query(max(st, (a+b)/2+1), dr, (a+b)/2+1, b, nod*2+1);
}
}
}
int main()
{
int n, m;
r>>n>>m;
int dim=1;
while(dim<n)
{
dim*=2;
}
dim--;
for(int i=1; i<=n; i++)
{
int x;
r>>x;
v[i+dim]=x;
update((i+dim)/2);
}
for(int i=0;i<m;i++){
int t, a, b;
r>>t>>a>>b;
if(t==1){
v[a+dim]=b;
update((a+dim)/2);
}
else{
maxim=0;
query(a+dim, b+dim, dim+1, dim*2+1, 1);
w<<maxim<<"\n";
}
}
return 0;
}