Pagini recente » Cod sursa (job #41519) | Cod sursa (job #3185948) | Cod sursa (job #754163) | Cod sursa (job #2727319) | Cod sursa (job #1069424)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
#define nmax 100001
#define bucket_dim 320
int i, j, N, M;
int vmax, t1, t2;
int op, a, b, st, dr;
int v[nmax];
int cnt, pos_a, pos_b, dim, buckets;
int bucket[bucket_dim];
int I[bucket_dim];
int main() {
fin >> N >> M;
dim = sqrt(1.0 * N);
I[0] = 1;
for (i = 1; i <= N; ++i, ++j) {
fin >> v[i];
if (j == dim) {
++cnt, j = 0;
I[cnt] = i;
}
bucket[cnt] = max(bucket[cnt], v[i]);
}
for (i = 1; i <= M; ++i) {
fin >> op >> a >> b;
if (op) {
--a;
v[a + 1] = b;
cnt = a / dim;
if (bucket[cnt] <= b) bucket[cnt] = b;
}
else {
--a;
--b;
vmax = 0;
t1 = a / dim;
t2 = b / dim;
pos_a = a % dim;
pos_b = b % dim;
if (t1 != t2) {
for (j = a + 1, cnt = pos_a; cnt <= dim; ++cnt, ++j) vmax = max(vmax, v[j]);
for (j = b + 1, cnt = pos_b; cnt >= 0; --cnt, --j) vmax = max(vmax, v[j]);
++t1;
--t2;
for (; t1 <= t2; ++t1)
vmax = max(vmax, bucket[t1]);
}
else {
for (j = a + 1, cnt = pos_a; cnt <= pos_b; ++cnt, ++j)
vmax = max(vmax, v[j]);
}
fout << vmax << '\n';
}
}
return 0;
}