Pagini recente » Cod sursa (job #678625) | Monitorul de evaluare | Cod sursa (job #1760594) | Cod sursa (job #1337278) | Cod sursa (job #3200320)
// sursa rebegea stefan
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n,m,sqrn;
int v[100000],batog[1000];
void update(int ind, int aux)
{
if(aux>=batog[ind/sqrn])
{
v[ind]=aux;
batog[ind/sqrn]=aux;
return ;
}
v[ind]=aux;
int l=ind/sqrn;
int r=l+1,bucket=l;
batog[bucket]=0;
while(l<r){
batog[bucket]=max(batog[bucket],v[l++]);
}
}
int getmax(int l , int r)
{
int ans=0;
int nextbuck,prevbuck;
nextbuck=((l/sqrn)+1)*sqrn;
prevbuck=(r/sqrn)*sqrn;
while(l<=r && l<nextbuck)
ans=max(ans,v[l++]);
while(r>=l && r>prevbuck)
ans=max(ans,v[r--]);
while(nextbuck<=prevbuck)
ans=max(ans,batog[nextbuck++]);
return ans;
}
int main()
{
int n,q;
cin>>n>>q;
sqrn=(int)sqrt(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
batog[i/sqrn]=max(batog[i/sqrn],v[i]);
}
bool tip;
int a1,a2;
while(q--)
{
cin>>tip>>a1>>a2;
if(tip)
update(a1-1,a2);
else
cout<<getmax(a1-1,a2-1)<<'\n';
}
return 0;
}