Pagini recente » Solutia problemei shoturi | Cod sursa (job #1725943) | Cod sursa (job #1598566) | Monitorul de evaluare | Cod sursa (job #1473352)
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#define BUCKET 256
#define bucket(x) ((x) / BUCKET)
#define DIM (1 << 13)
#define MAXN 100005
#define first(x) ((x) * BUCKET)
using namespace std;
int bpos = DIM, N, M, val[MAXN], MaxBuc[MAXN / BUCKET];
char buf[DIM];
inline int read_int(){
while (buf[bpos] > '9' || buf[bpos] < '0'){
++bpos;
if (bpos >= DIM) fread(buf, 1, DIM, stdin), bpos = 0;
}
int val = 0;
while (buf[bpos] >= '0' && buf[bpos] <= '9'){
val = val * 10 + buf[bpos++] - '0';
if (bpos == DIM) fread(buf, 1, DIM, stdin), bpos = 0;
}
return val;
}
inline void write(int k){
char lim[30], *s;
s = lim + 29, *s = 0;
do{
--s;
*s = k % 10 + '0';
k /= 10;
} while (k);
puts(s);
}
inline void update(){
int pos = read_int() - 1, value = read_int(), b = bucket(pos);
if (MaxBuc[b] == val[pos]){
MaxBuc[b] = val[pos] = 0;
for (int i = first(b); i < first(b + 1); ++i)
if (val[i] > MaxBuc[b]) MaxBuc[b] = val[i];
}
val[pos] = value;
if (value > MaxBuc[b]) MaxBuc[b] = value;
}
inline void query(){
int l = read_int() - 1, r = read_int() - 1, maxx = 0, b1 = bucket(l), b2 = bucket(r);
for (int i = b1 + 1; i < b2; ++i)
if (MaxBuc[i] > maxx) maxx = MaxBuc[i];
if (maxx < MaxBuc[b1])
for (; l < first(b1 + 1) && l <= r; ++l)
if (val[l] > maxx) maxx = val[l];
if (maxx < MaxBuc[b2])
for (; r >= first(b2) && r >= l; --r)
if (val[r] > maxx) maxx = val[r];
write(maxx);
}
int main(){
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
N = read_int(), M = read_int();
for (int i = 0; i < N; ++i){
val[i] = read_int();
if (MaxBuc[bucket(i)] < val[i]) MaxBuc[bucket(i)] = val[i];
}
while (M--)
if (read_int()) update();
else query();
return 0;
}