Pagini recente » Cod sursa (job #704967) | Cod sursa (job #801466) | Cod sursa (job #456089) | Cod sursa (job #801464) | Cod sursa (job #1409987)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int maxn = 100010;
int n, m, t, val, pos, a, b, x, y, best;
int arb[3 * maxn];
void updateArb(int node, int l, int r)
{
if (l == r)
{
arb[node] = val;
return;
}
int m = (l + r) >> 1;
if (pos <= m)
updateArb(2 * node, l, m);
else
updateArb(2 * node + 1, m + 1, r);
arb[node] = max(arb[2 * node], arb[2 * node + 1]);
}
void queryArb(int node, int l, int r)
{
if (l >= x && r <= y)
{
best = max(best, arb[node]);
return;
}
int m = (l + r) >> 1;
if (x <= m)
queryArb(2 * node, l, m);
if (m < y)
queryArb(2 * node + 1, m + 1, r);
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i++)
{
fin >> x;
val = x;
pos = i;
updateArb(1, 1, n);
}
for (; m; --m)
{
fin >> t >> a >> b;
if (t == 1)
{
val = b;
pos = a;
updateArb(1, 1, n);
}
else
{
best = -1;
x = a;
y = b;
queryArb(1, 1, n);
fout << best << '\n';
}
}
return 0;
}