Pagini recente » Cod sursa (job #1249513) | Cod sursa (job #1650927) | Cod sursa (job #2441906) | Cod sursa (job #1155312) | Cod sursa (job #384802)
Cod sursa(job #384802)
#include <stdio.h>
#define maxn 100010
#define BUCKET 256
#define bucket(x) ((x)/BUCKET)
#define first(x) ((x)*BUCKET)
unsigned max(unsigned a,unsigned b) {if(a>b) return a; return b; }
unsigned val[maxn],maxbuc[maxn/BUCKET],n,m,x,i,j;
void update(unsigned k,unsigned x)
{
unsigned b=bucket(k);
if(val[k]==maxbuc[b])
{
maxbuc[b]=val[k]=0;
for(unsigned i=first(b); i<first(b+1); i++)
if(val[i]>maxbuc[b]) maxbuc[b]=val[i];
}
val[k]=x;
if(x>maxbuc[b]) maxbuc[b]=x;
}
unsigned query(unsigned st,unsigned dr)
{
unsigned b1=bucket(st),b2=bucket(dr),sol=0;
for(unsigned i=b1+1; i<b2; i++)
if(maxbuc[i]>sol) sol=maxbuc[i];
if(sol<maxbuc[b1])
for(unsigned i=st; i<first(b1+1) && i<=dr; i++)
if(val[i]>sol) sol=val[i];
if(sol<maxbuc[b2])
for(unsigned i=max(first(b2),st); i<=dr; i++)
if(val[i]>sol) sol=val[i];
return sol;
}
int main()
{
freopen("arbint.in","r",stdin);
freopen("arbint.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=0; i<n; i++) { scanf("%d",&val[i]); if(val[i]>maxbuc[bucket(i)]) maxbuc[bucket(i)]=val[i]; }
for(; m>0; m--)
{
scanf("%d%d%d",&x,&i,&j);
if(x==1) update(i-1,j);
else printf("%d\n",query(i-1,j-1));
}
return 0;
}