Pagini recente » Cod sursa (job #1061875) | Cod sursa (job #2295952) | Cod sursa (job #2107615) | Clasament test12321321 | Cod sursa (job #2306683)
#include <iostream>
#include <fstream>
#include <cmath>
# define verf ++poz == hg ? f.read (ch, hg), poz = 0 : 0
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int hg = 1 << 13;
int poz,v[5];
char ch[hg];
inline void cit ( int &x ) {
if (ch[0] == '\0') f.read (ch, hg) ;
else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}
int n,m,a[100005],bucata[1005],index=-1,k;
void update(int poz,int val)
{
int i,start;
a[poz]=val;
start=k*(poz/k);
bucata[poz/k]=-1;
for(i=start;i<=start+k-1;i++)
{
bucata[poz/k]=max(bucata[poz/k],a[i]);
}
}
int query(int st,int dr)
{
int maxim=-1;
while(st<dr && st%k!=0 && st!=0)
{
maxim=max(maxim,a[st]);
st++;
}
while(st+k<=dr)
{
maxim=max(maxim,bucata[st/k]);
st=st+k;
}
while(st<=dr)
{
maxim=max(maxim,a[st]);
st++;
}
return maxim;
}
int main()
{
int i,st,dr,val,op,poz;
cit(n);
cit(m);
k=sqrt(n);
for(i=0;i<n;i++)
{
cit(a[i]);
if(i%k==0)
{
index++;
bucata[index]=-1;
}
bucata[index]=max(bucata[index],a[i]);
}
while(m--)
{
cit(op);
if(op==0)
{
cit(st);
cit(dr);
st--;
dr--;
g<<query(st,dr)<<"\n";
}
else
{
cit(poz);
cit(val);
poz--;
update(poz,val);
}
}
return 0;
}