Pagini recente » Cod sursa (job #1554997) | Cod sursa (job #1240716) | Cod sursa (job #1318795) | Cod sursa (job #801093) | Cod sursa (job #1849828)
#include <fstream>
using namespace std;
ifstream cin ("arbint.in");
ofstream cout ("arbint.out");
int n,m,key,poz,arb[500010],a,b;
void up_date (int st,int dr,int nod)
{
if(st>=poz && dr<=poz)
arb[nod]=key;
else
{
int mij=(st+dr)/2;
if(poz<=mij) up_date(st,mij,nod*2);
if(poz>mij) up_date(mij+1,dr,nod*2+1);
if(arb[nod*2]>arb[nod*2+1]) arb[nod]=arb[nod*2]; else arb[nod]=arb[nod*2+1];
}
}
void read ()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{ poz=i;
cin>>key;
up_date(1,n,1);
}
}
int figure_it_out (int st,int dr,int nod)
{
if(st>=a && dr<=b)
return arb[nod];
int mij=(st+dr)/2;
int x1=0,x2=0;
if(a<=mij) x1=figure_it_out(st,mij,nod*2);
if(b>mij) x2=figure_it_out(mij+1,dr,nod*2+1);
if(x1>x2) return x1;
return x2;
}
void solve_here_man ()
{ int h;
for(int i=1;i<=m;i++)
{
cin>>h>>a>>b;
if(h==0) cout<<figure_it_out(1,n,1)<<"\n";
else poz=a,key=b,up_date(1,n,1);
}
}
int main()
{
read();
solve_here_man();
cin.close();
cout.close();
return 0;
}