Pagini recente » Cod sursa (job #520795) | Cod sursa (job #229501) | Cod sursa (job #2593401) | Cod sursa (job #2919107) | Cod sursa (job #990723)
Cod sursa(job #990723)
using namespace std;
#include<fstream>
#include<algorithm>
#include<cmath>
ifstream eu("arbint.in");
ofstream tu("arbint.out");
#define Nmax 100002
int IT[1<<17];
int N,M,poz,val,QL,QR,QMax;
inline void Update(int nod,int L,int R)
{
int Mid=(L+R)/2;
if(L==R)
{
IT[nod]=val;
return;
}
if(poz<=Mid)
Update(2*nod,L,Mid);
else
Update(2*nod+1,Mid+1,R);
IT[nod]=max(IT[2*nod],IT[2*nod+1]);
}
inline int Query(int nod,int L,int R)
{
int Mid=(L+R)/2;
if(QL<=L&&R<=QR)
return IT[nod];
if(QL<=Mid)
QMax=max(QMax,Query(2*nod,L,Mid));
if(QR>Mid)
QMax=max(QMax,Query(2*nod+1,Mid+1,R));
return QMax;
}
int main()
{
int op;
eu>>N>>M;
for(poz=1;poz<=N;poz++)
{
eu>>val;
Update(1,1,N);
}
while(M--)
{
eu>>op;
if(op==0)
{
QMax=0;
eu>>QL>>QR;
tu<<Query(1,1,N)<<"\n";
}
if(op==1)
{
eu>>poz>>val;
Update(1,1,N);
}
}
return 0;
}