Cod sursa(job #154183)
#include <cstdio>
#include <algorithm>
#define MaxN 101000
#define BUCKET 256
#define Dim (1<<13)
#define bucket(x) ((x)/BUCKET)
#define first(x) ((x)*BUCKET)
using namespace std;
unsigned n, m, poz;
unsigned val[MaxN], maxBuc[MaxN/BUCKET];
char lin[Dim];
inline void cit(unsigned &x){
x=0;
while (lin[poz]<'0' || lin[poz]>'9'){
poz++;
if (poz == Dim) fread(lin, 1, Dim, stdin), poz=0;
}
while (lin[poz]>='0' && lin[poz]<='9'){
x = 10*x+lin[poz++]-'0';
if (poz == Dim) fread(lin, 1, Dim, stdin), poz=0;
}
}
inline void scrie(unsigned k){
char lin[30], *s;
s=lin+29; s[0]=0;
do {
unsigned cat=k/10;
s--;
s[0]=k-cat*10+'0';
k=cat;
} while (k);
puts(s);
}
inline void update(unsigned k, unsigned x){
unsigned b = bucket(k);
if (val[k]==maxBuc[b]){
maxBuc[b] = val[k] = 0;
for (unsigned i=first(b); i<first(b+1); i++)
if (val[i] > maxBuc[b]) maxBuc[b] = val[i];
}
val[k] = x;
if (x>maxBuc[b]) maxBuc[b] = x;
}
inline void query(unsigned st, unsigned fn){
unsigned b1 = bucket(st), b2 = bucket(fn);
unsigned sol = 0;
for (unsigned i=b1+1; i<b2; i++)
if (maxBuc[i] > sol) sol = maxBuc[i];
if (sol < maxBuc[b1])
for (unsigned i=st; i<first(b1+1) && i<=fn; i++)
if (val[i] > sol) sol = val[i];
if (sol < maxBuc[b2])
for (unsigned i=max(first(b2), st); i<=fn; i++)
if (val[i] > sol) sol = val[i];
scrie(sol);
}
int main(){
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
cit(n); cit(m);
for (unsigned i=0; i<n; i++){
cit(val[i]);
if (val[i] > maxBuc[bucket(i)]) maxBuc[bucket(i)] = val[i];
}
while (m--){
unsigned op, a, b;
cit(op); cit(a); cit(b);
if (op==1) update(a-1, b);
else query(a-1, b-1);
}
}