Pagini recente » Cod sursa (job #1372160) | Cod sursa (job #230977) | Cod sursa (job #2414551) | Cod sursa (job #2168087) | Cod sursa (job #642004)
Cod sursa(job #642004)
#include <fstream>
#define TSize 262145
using namespace std;
ifstream in;
ofstream out;
int T[TSize];
int pos,val;
int a,b;
inline void update(int nod,int L,int R)
{
if(L==pos&&pos==R)
{
T[nod]=val;
return;
}
int M=(L+R)>>1;
if(pos<=M) update(nod<<1,L,M);
else update((nod<<1)+1,M+1,R);
T[nod]=T[(nod<<1)+1];
if(T[nod]<T[nod<<1]) T[nod]=T[nod<<1];
}
inline int query(int nod,int L,int R)
{
if(a<=L&&R<=b) return T[nod];
int M=(L+R)>>1;
int x1=0,x2=0;
if(a<=M) x1=query(nod<<1,L,M);
if(b>M) x2=query((nod<<1)+1,M+1,R);
if(x1>x2) return x1;
return x2;
}
int main()
{
int M,N,x;
in.open("arbint.in");
in>>N>>M;
for(pos=1;pos<=N;++pos)
{
in>>val;
update(1,1,N);
}
out.open("arbint.out");
for(;M--;)
{
in>>x;
if(x)
{
in>>pos>>val;
update(1,1,N);
}
else
{
in>>a>>b;
out<<query(1,1,N)<<'\n';
}
}
in.close();
out.close();
}