Pagini recente » Rating Titiriga Tiberiu Nicolae (tiberiusss26) | Monitorul de evaluare | Monitorul de evaluare | Profil Crudu | Cod sursa (job #2843818)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int arb[400002], m, n;
void update(int val, int pos, int nod=1, int stg=1, int dr=n)
{
if (stg == dr)
{
arb[nod] = val;
return;
}
int mij = (stg+dr)/2;
if (pos <= mij)
{
update(val, pos, nod*2, stg, mij);
}
else
{
update(val, pos, nod*2+1, mij+1, dr);
}
arb[nod] = max(arb[nod*2], arb[nod*2+1]);
}
int query(int inc, int sf, int nod=1, int stg=1, int dr=n)
{
if (inc <= stg && dr <= sf)
{
return arb[nod];
}
int mij = (stg+dr)/2, r = -1;
if (inc <= mij)
{
r = max(r, query(inc, sf, nod*2, stg, mij));
}
if (mij < sf)
{
r = max(r, query(inc, sf, nod*2+1, mij+1, sf));
}
return r;
}
int main()
{
fin>>n>>m;
for (int i=1; i<=n; i++)
{
int x;
fin>>x;
update(x, i);
}
for (int i=1; i<=m; i++)
{
int op, p1, p2;
fin>>op>>p1>>p2;
if (op == 0)
{
fout<<query(p1, p2)<<'\n';
}
else
{
update(p2, p1);
}
}
fin.close();
fout.close();
return 0;
}