Pagini recente » Cod sursa (job #503323) | Cod sursa (job #1518497) | Cod sursa (job #1930193) | Cod sursa (job #2976338) | Cod sursa (job #3167733)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream in("arbint.in");
ofstream out("arbint.out");
const int bks=512, nmax=1e5+3;
int v[nmax], b[200], d[200];
const int len=512;
void UpdateBucket(int x)
{
int first=x*len, last=first+len-1;
b[x]=0;
for(int i=first; i<=last; i++)
{
b[x]=max(b[x], v[i]);
}
}
int query(int x, int y)
{
int rez=0;
int xbucket=x/len, ybucket=y/len;
int firstpos=len*xbucket, lastpos=(ybucket+1)*len-1;
if(ybucket-xbucket>=2)
{
for(int i=x; i<=firstpos; i++)
{
rez=max(rez, v[i]);
}
for(int i=xbucket; i<=ybucket; i++)
{
rez=max(rez, b[i]);
}
for(int i=lastpos; i<=y; i++)
{
rez=max(rez, v[i]);
}
}
else
{
for(int i=x; i<=y; i++)
{
rez=max(rez, v[i]);
}
}
return rez;
}
int main()
{
int n, m;
in>>n>>m;
for(int i=0; i<n; i++)
{
in>>v[i];
}
for(int i=0; i<n; i++)
{
b[i/len]=max(b[i/len], v[i]);
}
//DisplayB();
int op, x, y, maxi=0;
for(int i=0; i<m; i++)
{
in>>op>>x>>y; x--;
maxi=0;
if(op==1)
{
v[x]=y;
UpdateBucket(x/len);
//b[x/len]=max(b[x/len], v[x]);
}
else
{
y--;
out<<query(x, y)<<'\n';
}
}
//DisplayB();
}