Pagini recente » Cod sursa (job #1202856) | Cod sursa (job #1574591) | Istoria paginii runda/simulare_shumen_3/clasament | Cod sursa (job #1731630) | Cod sursa (job #539938)
Cod sursa(job #539938)
#include <fstream>
using namespace std;
#define DIM 400001
ifstream fi ("arbint.in");
ofstream fo ("arbint.out");
int N, M, A, B, R;
int Ar[DIM];
void update (int nod, int st, int dr)
{
if (dr == st)
{
Ar[nod] = B;
return;
}
int m = (st + dr) >> 1;
int nodst = nod << 1;
int noddr = nodst + 1;
if (A <= m)
update (nodst, st, m);
if (A > m)
update (noddr, m + 1, dr);
Ar[nod] = max (Ar[nodst], Ar[noddr]);
}
void query (int nod, int st, int dr)
{
if (A <= st && dr <= B)
{
R = max (R, Ar[nod]);
return;
}
int m = (st + dr) >> 1;
int nodst = nod << 1;
int noddr = nodst + 1;
if (A <= m)
query (nodst, st, m);
if (B > m)
query (noddr, m + 1, dr);
}
int main ()
{
fi >> N >> M;
for (int i = 1; i <= N; i++)
{
fi >> B; A = i;
update (1, 1, N);
}
for (int i = 1; i <= M; i++)
{
fi >> R >> A >> B;
if (R == 0)
{
query (1, 1, N);
fo << R << '\n';
}
else
update (1, 1, N);
}
return 0;
}