Pagini recente » Rating Crecana Constantin Cosmin (Crecana_Constantin_Cosmin_321CA) | Cod sursa (job #2816456) | Cod sursa (job #2904306) | Cod sursa (job #2617353) | Cod sursa (job #2203806)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int N = 1<<18;
struct nod
{
int M,L,R;
nod *fs,*fd;
};
nod *root,*make_tree(int,int);
void upd(nod*);
int n,m,o,x,y,get_max(nod*);
int main()
{
f>>n>>m;
root = make_tree(1,n);
for(;m;m--)
{
f>>o>>x>>y;
if(o==0)
g<<get_max(root)<<"\n";
else
upd(root);
}
return 0;
}
int get_max(nod *N)
{
if(x>N->R||y<N->L)
return 0;
if(x<=N->L&&N->R<=y)
return N->M;
return max(get_max(N->fs),get_max(N->fd));
}
nod *make_tree(int st,int dr)
{
nod *N=new nod;
if(st==dr)
{
N->L=N->R=st;
f>>N->M;
N->fs=N->fd=NULL;
}
else
{
int mi=(st+dr)/2;
N->L=N->R=st;
N->fs=make_tree(st,mi);
N->fd=make_tree(mi+1,dr);
N->M=max(N->fs->M,N->fd->M);
}
return N;
}
void upd(nod *N)
{
if(N->L==N->R)
{
N->M=y;
return;
}
if(x<=N->fs->R)
upd(N->fs);
else
upd(N->fd);
N->M=max(N->fs->M,N->fd->M);
}