Pagini recente » Cod sursa (job #1895580) | Cod sursa (job #917441) | Cod sursa (job #1849606) | Cod sursa (job #3292017) | Cod sursa (job #2916411)
#include <fstream>
std::ifstream in("arbint.in");
std::ofstream out("arbint.out");
struct nod {
int max, l, r;
nod *st, *dr;
};
nod *root = new nod;
int n, m, v[100001];
void cons(nod *root, int l, int r) {
root->l = l;
root->r = r;
if (l == r) {
root->max = v[l];
} else {
root->st = new nod;
root->dr = new nod;
cons(root->st, l, (l + r) / 2);
cons(root->dr, (l + r) / 2 + 1, r);
root->max = std::max(root->st->max, root->dr->max);
}
}
int max(nod *root, int l, int r) {
if (root->r < l || root->l > r) return -1;
if (r >= root->r && l <= root->l) return root->max;
return std::max(max(root->st, l, r), max(root->dr, l, r));
}
void update(nod *root, int ind, int newnum) {
if (root->l == root->r) {
root->max = newnum;
return;
};
if (ind <= (root->l + root->r) / 2)
update(root->st, ind, newnum);
else
update(root->dr, ind, newnum);
root->max = std::max(root->st->max, root->dr->max);
}
int main() {
in >> n >> m;
for (int i = 1; i <= n; i++) {
in >> v[i];
}
cons(root, 1, n);
for (int i = 0; i < m; i++) {
int c, a, b;
in >> c >> a >> b;
if (c == 0) {
out << max(root, a, b) << '\n';
} else if (c == 1) {
update(root, a, b);
}
}
}