Pagini recente » Cod sursa (job #1811848) | Cod sursa (job #2415886) | Cod sursa (job #2809512) | Cod sursa (job #1331545) | Cod sursa (job #1487262)
#include <fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int sz=1, arb[262145];
void build()
{
for(int nod=sz-1; nod; nod--)
arb[nod]=max(arb[nod<<1], arb[(nod<<1)|1]);
}
void update(int poz, int val)
{
int nod=poz+sz-1;
arb[nod]=val;
for(nod=nod>>1; nod; nod=nod>>1)
arb[nod]=max(arb[nod<<1], arb[(nod<<1)|1]);
}
int query(int st, int dr)
{
int rez=-1;
for(st=st+sz-1, dr=dr+sz-1; st<=dr; st=st>>1, dr=dr>>1)
{
if(st&1) rez=max(rez, arb[st++]);
if(!(dr&1)) rez=max(rez, arb[dr--]);
}
return rez;
}
int main()
{
int n, m, i, type, a, b;
fin >> n >> m;
while(sz<=n) sz=(sz<<1);
for(i=1; i<=n; i++)
fin >> arb[i+sz-1];
build();
while(m--)
{
fin >> type >> a >> b;
if(type == 0) fout << query(a, b) << '\n';
else update(a, b);
}
fin.close();
fout.close();
return 0;
}