Pagini recente » Cod sursa (job #2909447) | Cod sursa (job #2658865) | Cod sursa (job #43862) | Cod sursa (job #2091899) | Cod sursa (job #2572342)
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
pair<pair<int,int>,int> tree[200010];
int n, v[100005], N, M, cerinta, a, b;
void construire(int nod, int st, int dr)
{
tree[nod].f.f = st;
tree[nod].f.s = dr;
if(st == dr)
tree[nod].s = v[st];
else
{
int mij;
mij = (st + dr) / 2;
construire(2 * nod,st, mij);
construire(2 * nod + 1, mij + 1, dr);
tree[nod].s = max(tree[2*nod].s,tree[2 * nod + 1].s);
}
}
void maxim(int nod, int &maxx)
{
if(a <= tree[nod].f.f && tree[nod].f.s <= b)
{
maxx = max(maxx, tree[nod].s);
}
else
{
int mij = (tree[nod].f.f + tree[nod].f.s) / 2;
if(a <= mij)
maxim(2 * nod, maxx);
if(b > mij)
maxim(2 * nod + 1, maxx);
}
}
void update(int nod)
{
int st = tree[nod].f.f;
int dr = tree[nod].f.s;
int mij = (st + dr) / 2;
if(st == a && a == dr)
{
tree[nod].s = b;
}
else
{
if(a <= mij)
update(2 * nod);
else
update(2 * nod + 1);
tree[nod].s = max(tree[2 * nod].s, tree[2 * nod + 1].s);
}
}
int main()
{
int maxi;
fin >> N >> M;
for(int i=1; i<=N; i++)
fin >> v[i];
construire(1,1,N);
while(M)
{
maxi = 0;
fin >> cerinta >> a >> b;
if(!cerinta)
{
maxim(1, maxi);
fout << maxi << '\n';
}
else
{
update(1);
}
M--;
}
}