Cod sursa(job #245035)
#include <cstdio>
#define NX (1<<17)
#define INF (0x3f3f3f3f)
#define bit(i) (i & -i)
#define dim 8192
char ax[dim];
int pz;
inline void cit(int &x)
{
x=0;
while(ax[pz] < '0' || ax[pz] > '9')
if(++pz == dim) fread(ax,1,dim,stdin),pz=0;
while(ax[pz] >= '0' && ax[pz] <='9')
{
x=x*10+ax[pz]-'0';
if(++pz == dim) fread(ax,1,dim,stdin),pz=0;
}
}
inline void scrie(int x)
{
char lin[30], *s;
s=lin+29;s[0]=0;
int cat;
do
{
cat=x/10;
--s;
s[0]=x-cat*10+'0';
x=cat;
}while(x);
puts(s);
}
int T[ NX ], a[ NX ];
int N, M;
int que( int l, int r ) {
int m = 0;
while( l <= r )
if( r-bit(r)+1 >= l )
{
if(a[m] < a[ T[r] ]) m = T[r];
r -=bit(r);
}
else
{
if(a[m] < a[r]) m = r;
r--;
}
return m;
}
void upd( int x ) {
int y, z;
for(y = x; x <= N; x += bit(x))
if(T[x] == y)
{
z = que(x-bit(x) + 1, x-1);
T[x] = (a[z] > a[x]) ? z : x;
}
else
if(a[ T[x] ] < a[ y ])T[x] = y;
}
int main() {
int i, x, y, op;
freopen( "arbint.in", "r", stdin );
freopen( "arbint.out", "w", stdout );
a[0] = -INF;
cit(N); cit(M);
//scanf( "%d%d", &N, &M );
for( i = 1; i <= N; i++ ) {
cit(a[i]);
//scanf( "%d", a+i );
upd( i );
}
while( M-- ) {
cit(op); cit(x); cit(y);
//scanf( "%d%d%d", &op, &x, &y );
if( op == 0 )
scrie(a[que(x,y)]);//printf( "%d\n", a[ que( x, y ) ] );
else
a[x] = y, upd( x );
}
return 0;
}