Pagini recente » Cod sursa (job #2776670) | Cod sursa (job #2035154) | Cod sursa (job #1692634) | Cod sursa (job #1386192) | Cod sursa (job #2686441)
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int N_MAX = 700010;
int n, i, x, q, poz, maxi, val, a, b, start, finish, tree[N_MAX];
static inline void Update(int nod, int st, int dr)
{
if (st == dr)
{
tree[nod] = val;
return;
}
int m = (st + dr) / 2;
if (poz <= m)
Update(2 * nod, st, m);
else
Update(2 * nod + 1, m + 1, dr);
tree[nod] = max(tree[2 * nod], tree[2 * nod + 1]);
}
static inline void Query(int nod, int st, int dr)
{
if (start <= st && finish >= dr)
{
if (tree[nod] > maxi)
maxi = tree[nod];
return;
}
int m = (st + dr) / 2;
if (start <= m)
Query(2 * nod, st, m);
if (m < finish)
Query(2 * nod + 1, m + 1, dr);
}
int main()
{
f >> n >> q;
for (i = 1; i <= n; ++i)
{
f >> x;
poz = i;
val = x;
Update(1, 1, n);
}
for (i = 1; i <= q; ++i)
{
f >> x >> a >> b;
if (x == 0)
{
maxi = 0;
start = a;
finish = b;
Query(1, 1, n);
g << maxi << '\n';
}
else
{
poz = a;
val = b;
Update(1, 1, n);
}
}
return 0;
}