Pagini recente » Cod sursa (job #2637430) | Cod sursa (job #2529924) | Cod sursa (job #932293) | Cod sursa (job #403598) | Cod sursa (job #1994957)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
int n, m, x, pos, a, b, maxim;
int v[400008];
void update2(int st,int dr,int nod)
{
if (st==dr)
{
v[nod]=x;
return;
}
int mij=(st+dr)/2;
if (mij<pos)
update2(mij+1,dr,2*nod+1);
else
update2(st,mij,2*nod);
v[nod]=max(v[2*nod],v[2*nod+1]);
}
void update(int st, int dr)
{
stack <int> stiva;
int nod = 1, mij;
while(st<dr)
{
mij=(st+dr)/2;
stiva.push(nod);
if (mij<pos)
{
st = mij +1;
nod = 2*nod +1;
}
else
{
dr = mij;
nod = nod *2;
}
}
if (st==dr)
{
v[nod]=x;
//return;
}
//for (int i=1;i<=4*n+1;++i)
// cout<<v[i]<<" ";
///cout<<endl;
while(!stiva.empty())
{
v[stiva.top()]=max(v[stiva.top()*2], v[stiva.top()*2 + 1]);
stiva.pop();
}
//for (int i=1;i<=4*n+1;++i)
// cout<<v[i]<<" ";
//cout<<endl;
//cout<<endl;
}
void query (int st, int dr, int nod)
{
//cout<<nod<<"\n";
if (a <=st && b>=dr)
{
maxim=max(maxim,v[nod]);
return;
}
int mij=(st+dr)/2;
if (b>mij)
query(mij+1,dr,2*nod+1);
if (a<=mij)
query(st,mij,2*nod);
}
int main()
{
ifstream in ("arbint.in");
ofstream out ("arbint.out");
int i;
char c;
in>>n>>m;
for (i=1;i<=n;++i)
{
pos=i;
in>>x;
update(1, n);//, 1);
}
for(i=0;i<m;++i)
{
in>>c>>a>>b;
if(c=='0')
{
maxim = -1;
query(1, n, 1);
out<<maxim<<"\n";
}
if(c=='1')
{
x=b;
pos = a;
update(1, n);
}
//ce trebe facut
}
}