Pagini recente » Cod sursa (job #329614) | Cod sursa (job #1936134) | Cod sursa (job #1148615) | Cod sursa (job #516129) | Cod sursa (job #1140870)
#include <fstream>
using namespace std;
fstream f("arbint.in",ios::in);
fstream g("arbint.out",ios::out);
int poz,uj,a,b,kozep,maxi,n,m,q,x[500025],i,p;
int maximum(int a,int b)
{
if(a>b) return a;
else return b;
}
int update(int csp,int left,int right)
{
int kozep;
if(left==right)
{
x[csp]=uj;
return 0;
}
kozep=(left+right)/2;
if(poz<=kozep)
update(csp*2,left,kozep);
else update(csp*2+1,kozep+1,right);
x[csp]=maximum(x[2*csp],x[2*csp+1]);
}
int lekerdezes(int csp,int left,int right)
{
int kozep;
if(a<=left && right<=b)
{
if(maxi<x[csp])
maxi=x[csp];
return 0;
}
kozep=(left+right)/2;
if(a<=kozep) lekerdezes(2*csp,left,kozep);
if(kozep<b) lekerdezes(2*csp+1,kozep+1,right);
}
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>p;
poz=i;
uj=p;
update(1,1,n);
}
for(i=1;i<=m;i++)
{
f>>q>>a>>b;
if(q==0)
{
maxi=-1;
lekerdezes(1,1,n);
g<<maxi<<"\n";
}
if(q==1)
{
poz=a;
uj=b;
update(1,1,n);
}
}
}