Pagini recente » Cod sursa (job #1358263) | Cod sursa (job #2760854) | Cod sursa (job #901513) | Cod sursa (job #1480475) | Cod sursa (job #2422113)
//
// main.cpp
// arbint
//
// Created by Ciprian Ionescu on 5/17/19.
// Copyright © 2019 Ciprian Ionescu. All rights reserved.
//
#include <iostream>
#include <fstream>
#define MAX_N 100000
#define INF 1000000000
std::ifstream fin("arbint.in");
std::ofstream fout("arbint.out");
auto& in = fin;
auto& out = fout;
int pos, val, a, b;
int tree[MAX_N];
void update(const int p, const int begin, const int end) {
if (begin == end) {
tree[p] = val;
return;
}
const int m = (begin + end) / 2;
if (pos <= m) update(2 * p, begin, m);
else update(2 * p + 1, m + 1, end);
tree[p] = std::max(tree[2 * p], tree[2 * p + 1]);
}
int query(const int p, const int begin, const int end) {
if (a <= begin && end <= b) return tree[p];
const int m = (begin + end) / 2;
int max_begin = -INF, max_end = -INF;
if (a <= m) max_begin = query(2 * p, begin, m);
if (b > m) max_end = query(2 * p + 1, m + 1, end);
return std::max(max_begin, max_end);
}
int main(int argc, const char * argv[]) {
int n, m, c;
in >> n >> m;
for (int i = 1 ; i <= n ; i++) {
in >> val;
pos = i;
update(1, 1, n);
}
for (int i = 1 ; i <= m ; i++) {
in >> c;
if (c == 0) {
in >> a >> b;
out << query(1, 1, n) << '\n';
}
if (c == 1) {
in >> pos >> val;
update(1, 1, n);
}
}
return 0;
}