Pagini recente » Cod sursa (job #1261724) | Cod sursa (job #823927) | Cod sursa (job #1208215) | Cod sursa (job #2902235) | Cod sursa (job #1825477)
#include <fstream>
#include <algorithm>
int n, m, op_code, a, b;
int tree[200000];
void build()
{
for (int i = n - 1; i > 0; --i)
tree[i] = std::max(tree[i<<1], tree[i<<1|1]);
}
void modify(int position, int value)
{
for (tree[position += n] = value; position > 1; position >>= 1)
tree[position>>1] = std::max(tree[position] , tree[position^1]);
}
int query(int left, int right)
{
int result = -1;
for (left += n, right += n; left < right; left >>= 1, right >>= 1)
{
if (left&1) result = std::max(result, tree[left++]);
if (!(right&1)) result = std::max(result, tree[right--]);
}
return result;
}
int main()
{
std::ifstream fin("arbint.in");
std::ofstream fout("arbint.out");
fin>>n>>m;
for (int i = 0; i < n; ++i)
fin>>tree[n+i];
build();
for (int i = 0; i < m; ++i)
{
fin>>op_code>>a>>b;
if (op_code == 0)
fout<<query(a-1, b-1)<<"\n";
else if (op_code == 1)
modify(a-1, b);
}
fin.close();
fout.close();
return 0;
}