Pagini recente » Cod sursa (job #1733108) | Cod sursa (job #2840242) | Cod sursa (job #2840188) | Cod sursa (job #705993) | Cod sursa (job #1842955)
#include <cstdio>
#include <iostream>
#define zeros(x) (x&(x^(x-1)))
using namespace std;
FILE *f=fopen("arbint.in","r");
FILE *g=fopen("arbint.out","w");
int AIB[100005],V[100005];
int N,M,c,x,y;
int query(int l,int r)
{
int q,maxim=0;
while(r>=l)
{
if(r-zeros(r)+1>=l) q=AIB[r],r-=zeros(r);
else q=r,r=r-1;
if(V[maxim]<V[q])
maxim=q;
}
return maxim;
}
void update(int pos,int val)
{
V[pos]=val;
for(int x=pos;x<=N;x+=zeros(x))
{
if(AIB[x]==pos)
{
int z=query(x-zeros(x)+1,x-1);
if(V[z]>V[pos])AIB[x]=z;
}
else
{
if(V[pos]>V[AIB[x]])
AIB[x]=pos;
}
}
}
int main()
{
fscanf(f,"%d%d",&N,&M);
for(int i=1;i<=N;i++)
{
fscanf(f,"%d",&V[i]);
update(i,V[i]);
}
for(int i=1;i<=M;i++)
{
fscanf(f,"%d%d%d",&c,&x,&y);
if(!c)
fprintf(g,"%d\n",V[query(x,y)]);
else
update(x,y);
}
fclose(f);
fclose(g);
return 0;
}