Pagini recente » Cod sursa (job #2279508) | Cod sursa (job #888302) | Cod sursa (job #1924869) | Cod sursa (job #2363559) | Cod sursa (job #2864738)
#include <fstream>
#define MAXN 20000
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int start;
int a[4*MAXN];
void update(int newValue, int x){
a[x]=newValue;
while(x!=1){
x/=2;
a[x]=max(a[2*x], a[2*x+1]);
}
}
int query(int lo, int hi){
int leftValue=0, rightValue=0;
if(lo>hi)
return 0;
if(lo==hi)
return a[lo];
if(lo%2==1){
leftValue=a[lo];
lo++;
}
if(hi%2==0){
rightValue=a[hi];
hi--;
}
lo/=2, hi/=2;
return max(max(leftValue, rightValue), query(lo, hi));
}
int main()
{
int n, q; fin>>n>>q;
start=1;
while(start<n) start<<=1;
for(int i=start; i<start+n; i++){
fin>>a[i];
update(a[i], i);
}
for(int i=0; i<q; i++){
int op, x, y; fin>>op>>x>>y;
if(op==0){
fout<<query(x+start-1, y+start-1)<<'\n';
}
else{
update(y, x+start-1);
}
}
return 0;
}