Pagini recente » Cod sursa (job #594309) | Cod sursa (job #1637907) | Cod sursa (job #2966104) | Cod sursa (job #573519) | Cod sursa (job #1974152)
//try with sqrt
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int DIM=50000,nmax=100003,bmax=317;
int poz=DIM-1;
char buff[DIM];
void citeste(int &nr)
{
nr=0;
while(!('0'<=buff[poz]&&buff[poz]<='9'))
{
if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
}
while('0'<=buff[poz]&&buff[poz]<='9')
{
nr=nr*10 + buff[poz]-'0';
if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
}
}
int v[nmax],s[bmax];
unsigned char piece[nmax];
int n,m,x;
inline void citire()
{
citeste(n),citeste(m);
x=sqrt(n);
for(int i=1;i<=n;i++) citeste(v[i]);
int pieceT=0;
for(int i=1;i<=n;i+=x)
{
++pieceT;
for(int j=i;j<i+x&&j<=n;j++)
{
piece[j]=pieceT;
s[pieceT]=max(s[pieceT],v[j]);
}
}
}
int query1(int p1,int p2)
{
int maxim=0;
for(int i=p1;i<=p2;i++)
{
if(piece[i]!=piece[i-1]&&i+x-1<=p2)
{
maxim=max(maxim,s[piece[i]]);
i+=x;
--i;
}
else maxim=max(maxim,v[i]);
}
return maxim;
}
inline void solve()
{
for(;m>0;--m)
{
int tip;
citeste(tip);
if(tip==1)
{
int a,b;
citeste(a),citeste(b);
v[a]=b;
s[piece[a]]=0;
for(int i=x*(piece[a]-1)+1;i<=x*(piece[a])&&i<=n;i++) s[piece[a]]=max(s[piece[a]],v[i]);
}
else
{
int a,b;
citeste(a),citeste(b);
printf("%d\n",query1(a,b));
}
}
}
int main()
{
freopen ("arbint.in","r",stdin);
freopen ("arbint.out","w",stdout);
citire();
solve();
}