Pagini recente » Cod sursa (job #2271668) | Cod sursa (job #1341531) | Cod sursa (job #1514844) | Cod sursa (job #1744856) | Cod sursa (job #1850544)
#include <fstream>
using namespace std;
ifstream cin ("arbint.in");
ofstream cout ("arbint.out");
int key,poz,arb[500001],n,m,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);
else 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++)
cin>>key,poz=i,up_date(1,n,1);
}
int ask_me (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=ask_me(st,mij,nod*2);
if(b>mij) x2=ask_me(mij+1,dr,nod*2+1);
if(x1>x2) return x1; else return x2;
}
void solve_here ()
{ int c;
for(int i=1;i<=m;i++)
{
cin>>c>>a>>b;
if(c==1) poz=a,key=b,up_date(1,n,1);
else cout<<ask_me(1,n,1)<<"\n";
}
}
int main()
{
read();
solve_here();
cin.close();
cout.close();
return 0;
}