Pagini recente » Cod sursa (job #2289010) | Cod sursa (job #2959433) | Cod sursa (job #1437131) | Cod sursa (job #3264444) | Cod sursa (job #1069355)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <deque>
#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;
int v[nmax];
int cnt, pos_a, pos_b, dim, buckets;
deque <int> bucket[bucket_dim];
deque <int> :: iterator it, it_start, it_end;
int main() {
fin >> N >> M;
dim = sqrt(1.0 * N);
buckets = (N / dim) + 1;
for (i = 1; i <= N; ++i) {
fin >> v[i];
if (bucket[cnt].size() == dim)
++cnt;
bucket[cnt].push_back(v[i]);
}
/*
for (i = 0; i < buckets; ++i) {
for (it = bucket[i].begin(); it != bucket[i].end(); ++it)
cout << *it << ' ';
cout << '\n';
}
*/
for (i = 1; i <= M; ++i) {
fin >> op >> a >> b;
if (op) {
--a;
cnt = a / dim;
pos_a = a % dim;
for (j = 1, it = bucket[cnt].begin(); it != bucket[cnt].end(); ++it, ++j) {
if (j - 1 == pos_a) {
*it = b;
break;
}
}
}
else {
--a;
--b;
vmax = 0;
t1 = a / dim;
pos_a = a % dim;
pos_b = b % dim;
t2 = b / dim;
for (; t1 <= t2; ++t1) {
it_start = bucket[t1].begin();
it_end = bucket[t1].end();
if (t1 == (a / dim)) it_start = bucket[t1].begin() + pos_a;
if (t1 == (b / dim)) it_end = bucket[t1].begin() + pos_b, ++it_end;
for (; it_start != it_end; ++it_start)
vmax = max(vmax, *it_start);
}
fout << vmax << '\n';
}
}
return 0;
}