Pagini recente » Cod sursa (job #2226863) | Cod sursa (job #2286020) | Cod sursa (job #2450269) | Cod sursa (job #551638) | Cod sursa (job #1617877)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int nmax = 100005;
int dim=1, arb[nmax<<1];
void update(int poz, int val)
{
int i=poz+dim-1;
arb[i]=val;
for(i=i>>1; i; i=i>>1)
arb[i]=max(arb[i<<1], arb[(i<<1)|1]);
}
void query(int st, int dr)
{
int maxx=0, nr;
st=st+dim-1;
dr=dr+dim-1;
while(st<=dr)
{
nr=max(arb[st], arb[dr]);
maxx=max(maxx, nr);
st=(st+1)>>1;
dr=(dr-1)>>1;
}
fout << maxx << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
int n, m, i, type, a, b;
fin >> n >> m;
while(dim<=n)
dim=dim<<1;
for(i=1; i<=n; i++)
fin >> arb[i+dim-1];
while(m--)
{
fin >> type >> a >> b;
if(type == 0) query(a, b);
else update(a, b);
}
fin.close();
fout.close();
return 0;
}