Pagini recente » Cod sursa (job #1368709) | Cod sursa (job #2944187)
#include <fstream>
using namespace std;
int aint[100000 * 4 + 5];
int v[100005];
struct interval
{
int st, dr;
};
void update(int el, int nod, int pos, interval x)
{
if(x.st == x.dr)
{
aint[nod] = el;
return;
}
interval a = {x.st, (x.st + x.dr) / 2};
interval b = {(x.st + x.dr) / 2 + 1, x.dr};
int mij = (x.st + x.dr) / 2;
if(pos <= mij)
update(el, nod * 2, pos, a);
if(pos >= mij + 1)
update(el, nod * 2 + 1, pos, b);
aint[nod] = max(aint[nod * 2 + 1], aint[nod * 2]);
return;
}
int maxx = 0;
void query(interval fin, interval x, int nod)
{
if(x.st >= fin.st && x.dr <= fin.dr)
{
maxx = max(maxx, aint[nod]);
return;
}
interval a = {x.st, (x.st + x.dr) / 2};
interval b = {(x.st + x.dr) / 2 + 1, x.dr};
if(fin.st <= a.dr)
query(fin, a, nod * 2);
if(fin.dr >= a.dr + 1)
query(fin, b, nod * 2 + 1);
return;
}
int main()
{
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n, q;
cin>>n>>q;
for(int i = 1; i <= n; i++)
{
cin>>v[i];
update(v[i], 1, i, {1, n});
}
for(int i = 1; i <= q; i++)
{
bool cer;
int st, dr;
cin>>cer>>st>>dr;
if(cer == false)
{
maxx = 0;
query({st, dr}, {1, n}, 1);
cout<<maxx<<'\n';
}
else
{
update(dr, 1, st, {1, n});
}
}
return 0;
}