Pagini recente » Cod sursa (job #1743075) | Cod sursa (job #1685802) | Cod sursa (job #361270) | Cod sursa (job #2115409) | Cod sursa (job #1069375)
#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 main() {
fin >> N >> M;
dim = sqrt(1.0 * N);
buckets = (N / dim) + 1;
for (i = 1; i <= N; ++i) {
fin >> v[i];
if (j == dim)
++cnt, j = 0;
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;
bucket[cnt] = max(bucket[cnt], b);
}
else {
--a;
--b;
vmax = 0;
t1 = a / dim;
t2 = b / dim;
pos_a = a % dim;
pos_b = b % dim;
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]);
fout << vmax << '\n';
}
}
return 0;
}