Pagini recente » Cod sursa (job #991421) | Cod sursa (job #368940) | Cod sursa (job #3159464) | Cod sursa (job #1771365) | Cod sursa (job #185832)
Cod sursa(job #185832)
using namespace std;
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#define N 101001
#define sqr 256
#define bucket(x) ( (x)/sqr)
#define first(x) ((x)*sqr)
#define DIM (1<<13)
int x[N], b[N/sqr];
int n,m;
char ax[DIM];
int poz;
inline void cit(int &x)
{
x=0;
while(ax[poz]<'0' || ax[poz]>'9')
{
++poz;
if(poz==DIM) fread(ax, 1, DIM, stdin), poz=0;
}
while(ax[poz]>='0' && ax[poz]<='9')
{
x=x*10+ax[poz]-'0';
++poz;
if(poz==DIM) fread(ax, 1, DIM, stdin), poz=0;
}
}
inline void update(int p, int v)
{
int bb=bucket(p);
x[p]=v;
int i;
b[bb]=0;
for(i=first(bb); i< first(bb+1);++i)
b[bb]=max(b[bb], x[i]);
}
inline int query(int l, int r)
{
int sol=0,i;
int b1=bucket(l), b2=bucket(r);
for(i=l;i<first(b1+1) && i<=r; ++i) sol=max(x[i], sol);
for(i=max(first(b2), l); i<=r; ++i) sol=max(sol, x[i]);
for(i=b1+1; i<b2; ++i) sol=max(b[i], sol);
return sol;
}
int main()
{
freopen("arbint.in","r",stdin);
freopen("arbint.out","w",stdout);
cit(n);cit(m);
// scanf("%d %d\n", &n,&m);
int i,v;
for(i=1;i<=n;++i){cit(v);update(i-1,v);}
int t, p, q;
while(m--)
{
cit(t); cit(p); cit(q);
//scanf("%d %d %d\n", &t, &p, &q);
if(t==0) printf("%d\n", query(p-1, q-1));
else update(p-1,q);
}
return 0;
}