Pagini recente » Borderou de evaluare (job #2671008) | Cod sursa (job #2882613)
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#if 1
#include <fstream>
ifstream fin("arbint.in");
ofstream fout("arbint.out");
#define cin fin
#define cout fout
#endif
const int nmx = 100000 + 10;
int arb[(1 << 18)]; // [0,n]
int n, m;
int upVal, upst, updr;
int arr[nmx];
void Afisare()
{
cout << "#######\n";
int k = 1;
for(int i=1;i<=5;i++,cout << "\n")
for (int j = 0; j < (1<<(i-1)); j++)
{
cout << arb[k++] << " ";
}
cout << "#######\n";
}
void Fill(int nod, int st, int dr)
{
if (st == dr) {
arb[nod] = arr[st];
return;
}
int md = (st + dr) / 2;
Fill(2 * nod, st, md);
Fill(2 * nod+1, md + 1, dr);
arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}
void Update(int nod, int st, int dr)
{
if (upst <= st && dr <= updr)
{
arb[nod] = upVal;
return;
}
int md = (st + dr) / 2;
if (upst <= md) Update(2 * nod, st, md);
if (md < updr) Update(2 * nod + 1, md + 1, dr);
arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}
int Query(int nod, int st, int dr)
{
if (upst <= st && dr <= updr)
{
return arb[nod];
}
int md = (st + dr) / 2;
int q1, q2;
if (upst <= md)q1 = Query(2 * nod, st, md);
if (md < updr)q2 = Query(2 * nod + 1, md + 1, dr);
return max(q1, q2);
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
Fill(1, 1, n);
while (m--)
{
int op, a, b;
cin >> op >> a >> b;
if (op == 0)
{
upst = a, updr = b;
cout << Query(1, 1, n) << endl;
}
else
{
upst = a, updr = a;
upVal = b;
Update(1, 1, n);
}
}
}