Pagini recente » Cod sursa (job #302283) | Cod sursa (job #2752776) | Statistici Nechita Stefan (karow) | Cod sursa (job #2904005) | Cod sursa (job #1005436)
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
constexpr size_t MAXN = 100010 * 3;
size_t tree[MAXN];
size_t update_val, update_pos, max_left, max_right, max_search;
void update(const size_t nod, const size_t l, const size_t r)
{
if (l == r)
{
tree[nod] = update_val;
return;
}
size_t m = l + (r-l)/2;
if (update_pos <= m) update(2*nod, l, m);
else update(2*nod+1, m+1, r);
tree[nod] = max(tree[2*nod], tree[2*nod+1]);
}
void query(const size_t nod, const size_t l, const size_t r)
{
if (max_left <= l && r <= max_right)
{
max_search = max(max_search, tree[nod]);
return;
}
size_t m = l + (r - l)/2;
if (max_left <= m) query(2*nod, l, m);
if (m < max_right) query(2*nod+1, m+1, r);
}
int main()
{
ifstream fin("arbint.in");
ofstream fout("arbint.out");
size_t n, nr_queries, op, a, b;
fin >> n >> nr_queries;
for(update_pos = 1; update_pos <= n; ++update_pos)
{
fin >> update_val;
update(1, 1, n);
}
for(; nr_queries; nr_queries--)
{
fin >> op >> a >> b;
if (op == 0)
{
max_search = 0;
max_left = a;
max_right = b;
query(1, 1, n);
fout << max_search << '\n';
}
else
{
update_pos = a;
update_val = b;
update(1, 1, n);
}
}
return 0;
}