Pagini recente » Cod sursa (job #1769722) | Cod sursa (job #268385) | Cod sursa (job #2907611) | Cod sursa (job #855803) | Cod sursa (job #2572394)
#include <fstream>
#include <vector>
#define f first
#define s second
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
int n, m, v[100005], cer, st, dr, a, b, poz, val, maxi;
pair<pair<int, int>, int> arb[500005];
void construire (int nod, int st, int dr)
{
int mij;
arb[nod].f.f=st;
arb[nod].f.s=dr;
if (st==dr)
{
arb[nod].s=v[st];
}
else
{
mij=(st+dr)/2;
construire(2*nod, st, mij);
construire(2*nod+1, mij+1, dr);
if (arb[2*nod].s>arb[2*nod+1].s)
arb[nod].s=arb[2*nod].s;
else
arb[nod].s=arb[2*nod+1].s;
}
}
void maxim (int nod)
{
int st, dr, mij, val;
st=arb[nod].f.f;
dr=arb[nod].f.s;
if (st>=a && dr<=b)
{
if (arb[nod].s>maxi)
maxi=arb[nod].s;
}
else
{
mij=(st+dr)/2;
if (a<=mij)
maxim(2*nod);
if (b>=mij+1)
maxim(2*nod+1);
}
}
void actualizare (int nod)
{
int st, dr, mij;
st=arb[nod].f.f;
dr=arb[nod].f.s;
if (st==poz && dr==poz)
{
arb[nod].s=val;
}
else
{
mij=(st+dr)/2;
if (poz<=mij)
actualizare(2*nod);
else
actualizare(2*nod+1);
if (arb[2*nod].s>arb[2*nod+1].s)
{
arb[nod].s=arb[2*nod].s;
}
else
{
arb[nod].s=arb[2*nod+1].s;
}
}
}
int main()
{
int i;
fin>>n>>m;
for (i=1; i<=n; i++)
{
fin>>v[i];
}
construire(1, 1, n);
for (i=1; i<=m; i++)
{
fin>>cer;
if (cer==0)
{
fin>>a>>b;
maxi=0;
maxim(1);
fout<<maxi<<'\n';
}
else
{
fin>>poz>>val;
actualizare(1);
}
}
fin.close();
fout.close();
return 0;
}