Pagini recente » Cod sursa (job #1564636) | Autentificare | Cod sursa (job #2813078) | Cod sursa (job #2690400) | Cod sursa (job #2572441)
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
pair<pair<int,int>,int> arb[500010];
int n, m, v[500010], maxx=0, x, y;
void construire (int nod, int st, int dr)
{
int mij;
arb[nod].first.first=st;
arb[nod].first.second=dr;
if (st==dr)
arb[nod].second=v[st];
else
{
mij=(st+dr)/2;
construire(2*nod, st, mij);
construire(2*nod+1, mij+1, dr);
arb[nod].second=max(arb[2*nod].second, arb[2*nod+1].second);
}
}
int maxim (int nod)
{
int mij;
if (x<=arb[nod].first.first && arb[nod].first.second<=y)
maxx=max(maxx, arb[nod].second);
else
{
mij=(arb[nod].first.first+arb[nod].first.second)/2;
if (x<=mij) maxim(2*nod);
if (y>mij) maxim(2*nod+1);
}
}
void actualizare (int nod)
{
int mij;
if (x==arb[nod].first.first && x==arb[nod].first.second)
arb[nod].second=y;
else
{
mij=(arb[nod].first.first+arb[nod].first.second)/2;
if (x<=mij) actualizare(2*nod);
else actualizare(2*nod+1);
arb[nod].second=max(arb[2*nod].second, arb[2*nod+1].second);
}
}
int main ()
{
int i;
fin>>n>>m;
for (i=1; i<=n; i++)
fin>>v[i];
int cer;
construire(1, 1, n);
for (i=1; i<=m; i++)
{
fin>>cer>>x>>y;
if (cer==0)
{
maxx=0;
maxim(1);
fout<<maxx<<'\n';
}
else actualizare(1);
}
}