Pagini recente » Cod sursa (job #1088972) | Cod sursa (job #1042287) | Cod sursa (job #2147231) | Cod sursa (job #1911838) | Cod sursa (job #1379924)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int n, m, arb[3 * MAXN], x, y, a, b, val, pos, tip, maxim;
void update(int node, int l, int r)
{
if (l == r)
{
arb[node] = val;
return;
}
int m = (l + r) / 2;
if (pos <= m)
update(2 * node, l, m);
else
update(2 * node + 1, m + 1, r);
arb[node] = max(arb[2 * node], arb[2 * node + 1]);
}
void query(int node, int l, int r)
{
if (l >= x && r <= y)
{
maxim = max(maxim, arb[node]);
return;
}
int m = (l + r) / 2;
if (x <= m)
query(2 * node, l, m);
if (m < y)
query(2 * node + 1, m + 1, r);
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; ++i)
{
fin >> x;
val = x;
pos = i;
update(1, 1, n);
}
for (; m; --m)
{
fin >> tip >> a >> b;
if (tip == 1)
{
pos = a;
val = b;
update(1, 1, n);
}
else
{
x = a;
y = b;
maxim = -1;
query(1, 1, n);
fout << maxim << '\n';
}
}
return 0;
}