Pagini recente » Cod sursa (job #2940516) | Cod sursa (job #401585) | Cod sursa (job #2257405) | Cod sursa (job #504254) | Cod sursa (job #2301405)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int pom[400005],v[100005];
int pos, val, ql, qr, ans;
void build(int nod, int st, int dr)
{
if (st == dr)
pom[nod] = v[st];
else
{
int med = (st + dr) / 2;
build(2 * nod, st, med);
build(2 * nod + 1, med + 1, dr);
pom[nod] = max(pom[2 * nod], pom[2 * nod + 1]);
}
}
void update(int nod, int st, int dr)
{
if (st == dr)
{
pom[nod] = val;
return;
}
int md = (st + dr) / 2;
if (pos <= md)
update(2 * nod, st, md);
else
update(2 * nod + 1, md + 1, dr);
pom[nod] = max(pom[2 * nod], pom[2 * nod + 1]);
}
int query(int nod, int st, int dr)
{
if (ql <= st && dr <= qr)
return pom[nod];
int md = (st + dr) / 2;
ans = -99999999;
if (ql <= md)
ans = max(ans, query (2 * nod, st, md));
else
ans = max(ans, query (2 * nod + 1, md + 1, dr));
return ans;
}
int main()
{
int n,m,a,b;
bool ok;
fin >> n >> m;
for (int i = 1;i <= n;i++)
fin >> v[i];
build(1, 1, n);
for (int i = 1;i <= m;i++)
{
fin >> ok >> a >> b;
if (ok == 1)
{
pos = a;
val = b;
update(1, 1, n);
}
else
{
ans = 0;
ql = a;
qr = b;
fout << query(1, 1, n) << '\n';
}
}
return 0;
}