Pagini recente » Cod sursa (job #1134257) | Cod sursa (job #1888472) | Cod sursa (job #2775495) | Cod sursa (job #2420791) | Cod sursa (job #1919725)
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
int H,nrbuc;
int n,m;
int a[100003],buc[100003],b[403];
int Query(int x,int y)
{
int poz,maxim;
maxim=-INF;
poz=buc[x] + 1;
while(poz<buc[y])
{
maxim=max(maxim,b[poz]);
poz++;
}
poz=x;
while(buc[poz]==buc[x])
{
maxim=max(maxim,a[poz]);
poz++;
}
poz=y;
while(buc[poz]==buc[y])
{
maxim=max(maxim,a[poz]);
poz--;
}
return maxim;
}
void Update(int poz,int x)
{
a[poz]=x;
if(b[buc[poz]]>x)
b[buc[poz]]=x;
}
int main()
{
int i,x,y,op;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
fin>>n>>m;
for(i=1;i<=n;++i)
fin>>a[i];
H=int(sqrt(n));
for(i=1;i<=H+1;++i)
b[i]=-INF;
for(i=1;i<=n;++i)
{
buc[i]=i/H + 1;
if(i%H==0) buc[i]--;
b[buc[i]]=max(b[buc[i]],a[i]);
}
nrbuc=buc[n];
///sol
for(i=1;i<=m;++i)
{
fin>>op>>x>>y;
if(op==0)
fout<<Query(x,y)<<"\n";
else
Update(x,y);
}
return 0;
}