Pagini recente » Cod sursa (job #12197) | Cod sursa (job #1133123)
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
FILE *f,*g;
struct Arborel
{
int maxim;
};
int p2=1;
Arborel nod[300000];
void update(int a,int b)
{
nod[a+p2].maxim=b;
a+=p2;a/=2;
while (a)
{
nod[a].maxim=max(nod[a*2].maxim,nod[a*2+1].maxim);
a/=2;
}
}
void query(int a,int b)
{
a+=p2;b+=p2;
int max1=nod[a].maxim,max2=nod[b].maxim;
while(a/2!=b/2)
{
if (a%2==0) max1=max(max1,nod[a+1].maxim);
if (b%2==1) max2=max(max2,nod[b-1].maxim);
a/=2;b/=2;
}
max1=max(max1,max2);
fprintf(g,"%d\n",max1);
}
int main()
{
int a,b,x,N,M,i;
f=fopen("arbint.in","r");
g=fopen("arbint.out","w");
fscanf(f,"%d%d",&N,&M);
while (p2<N) p2<<=1;
p2--;
for(i=1;i<=N;i++)
{
fscanf(f,"%d",&x);
update(i,x);
}
for(i=1;i<=M;i++)
{
fscanf(f,"%d%d%d",&x,&a,&b);
if (x) update(a,b);
else query(a,b);
}
return 0;
}