Pagini recente » Cod sursa (job #918210) | Cod sursa (job #949088) | Cod sursa (job #912429) | Cod sursa (job #2065703) | Cod sursa (job #1190394)
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
class SegmentTree {
public:
SegmentTree() {}
SegmentTree(const int _N)
{
for (N = 1; N < _N; N <<= 1);
Aint = vector<int> (2 * N + 3, 0);
}
void update(int poz, const int val)
{
Aint[poz += N] = val;
for (poz >>= 1; poz; poz >>= 1)
Aint[poz] = max(Aint[2 * poz], Aint[2 * poz + 1]);
}
int query(int left, int right)
{
left += N;
right += N;
int ret = 0;
while (left <= right)
{
ret = max(ret, max(Aint[left], Aint[right]));
left = (left + 1) >> 1;
right = (right - 1) >> 1;
}
return ret;
}
private:
vector<int> Aint;
int N;
};
SegmentTree A;
int main()
{
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
int N, Q;
scanf("%d%d", &N, &Q);
A = SegmentTree(N);
for (int i = 1; i <= N; i++)
{
int x;
scanf("%d", &x);
A.update(i, x);
}
while (Q--)
{
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if (op == 1)
A.update(x, y);
else
printf("%d\n", A.query(x, y));
}
}