Pagini recente » Cod sursa (job #1057280) | Cod sursa (job #2718543) | Cod sursa (job #2147083) | Cod sursa (job #1790986) | Cod sursa (job #760873)
Cod sursa(job #760873)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int copacel_max[4*100001];
int poz, maxim, n, m, i, val, x, y;
bool op;
void Update(int nod, int st, int dr)
{
if ( st!= dr )
{
int mij = (st+dr)/2;
if ( poz <= mij )
{
Update(2*nod,st,mij);
}
else
Update(2*nod+1,mij+1,dr);
}
else
{
copacel_max[nod] = val;
return;
}
copacel_max[nod] = max(copacel_max[2*nod],copacel_max[2*nod+1]);
}
void Query(int nod, int st, int dr)
{
if ( x <= st && y >= dr )
{
if ( copacel_max[nod] > maxim )
maxim = copacel_max[nod];
return;
}
int mij = (st+dr)/2;
if ( x <= mij )
{
Query(2*nod,st,mij);
}
if ( y > mij )
{
Query(2*nod+1,mij+1,dr);
}
}
int main()
{
fin >> n >> m;
for ( i = 1; i<= n; i++ )
{
fin >> val;
poz = i;
Update(1,1,n);
}
for ( i = 1; i <= m; i++ )
{
fin >> op >> x >> y;
if ( !op )
{
maxim = -1;
Query(1,1,n);
fout << maxim << '\n';
}
else
{
poz = x, val = y;
Update(1,1,n);
}
}
fin.close();
fout.close();
return 0;
}