Pagini recente » Cod sursa (job #1617483) | Cod sursa (job #410164) | Cod sursa (job #1293069) | Cod sursa (job #2818440) | Cod sursa (job #2284014)
#include<stdio.h>
#include<iostream>
#include<fstream>
using namespace std;
typedef struct node{
int a, b;
int maxim;
node *left,* right;
}node;
node* arbore=NULL;
#define MAXN 100000
int M,N;
int V[MAXN];
#define maxim(x,y) x>y?x:y
node* buildtree(int l,int r){
node* aux=new node;
if(l==r){
aux->left=aux->right=NULL;
aux->a=aux->b=l;
aux->maxim=V[l];
return aux;
}
int mid=(l+r)/2;
aux->a=l;
aux->b=r;
aux->left=buildtree(l,mid);
aux->right=buildtree(mid+1,r);
aux->maxim=maxim(aux->left->maxim,aux->right->maxim);
return aux;
}
int a,b;
int findmax(node* root){
if(a<=root->a && b>=root->b)
return root->maxim;
int mid=(root->a+root->b)/2;
int max1=0,max2=0;
if(a<=mid)
max1=findmax(root->left);
if(b>mid)
max2=findmax(root->right);
return maxim(max1,max2);
}
int index;
int value;
void replacenode(node* root){
int mid;
if(root->a!=root->b){
mid=(root->a+root->b)/2;
if(index<=mid)
replacenode(root->left);
else
replacenode(root->right);
root->maxim=maxim(root->left->maxim,root->right->maxim);
return;
}
root->maxim=value;
}
int main(){
freopen("arbint.in", "r", stdin);
//freopen("arbint_test10.in", "r", stdin);
freopen("arbint.out", "w", stdout);
scanf("%d %d", &N,&M);
for(int i=0;i<N;i++)
scanf("%d", &V[i]);
arbore=buildtree(0,N-1);
int tip,x,y,max;
for(int i=0;i<M;i++){
scanf("%d %d %d",&tip,&x,&y);
if(tip==0){
a=x-1;
b=y-1;
max=findmax(arbore);
printf("%d\n",max);
}
else{
index=x-1;
value=y;
replacenode(arbore);
}
}
return 0;
}