Pagini recente » Cod sursa (job #1213909) | Cod sursa (job #1952004) | Cod sursa (job #1140809)
#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[100005],i;
int maximum(int a,int b)
{
if(a>b) return a;
else return b;
}
int update(int csp,int left,int right)
{
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)
{
maxi=-1;
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>>x[i];
for(i=1;i<=m;i++)
{
f>>q;
if(q==0)
{
f>>a>>b;
lekerdezes(1,1,n);
g<<maxi<<"\n";
}
if(q==1)
{
f>>poz>>uj;
update(1,1,n);
}
}
}