Pagini recente » Cod sursa (job #1880424) | Cod sursa (job #1752931) | Cod sursa (job #3124119) | Cod sursa (job #1522156) | Cod sursa (job #967176)
Cod sursa(job #967176)
#include <fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout ("arbint.out");
int t[1<<17],a,b;
void update (int nod, int st, int dr)
{
int i=nod<<1,j=(nod<<1)+1;
if (st<dr)
{
int m=(st+dr)>>1;
if (a<=m)
update (i,st,m);
else
update (j,m+1,dr);
}
else {t[nod]=b; return;}
if (t[i]>t[j]) t[nod]=t[i];
else t[nod]=t[j];
}
int query (int nod, int st, int dr)
{
if (st<a||b<dr)
{
int m=(st+dr)>>1;
int x=0,y=0;
if (a<=m) x=query(nod<<1,st,m);
if (b>m) y=query ((nod<<1)+1,m+1,dr);
if (x<y) x=y;
return x;
}
else return t[nod];
}
int main()
{
int n,m,i,x; bool op;
fin>>n>>m;
for (a=1;a<=n;a++) {fin>>b; update (1,1,n);}
for (i=1;i<=m;i++)
{
fin>>op>>a>>b;
if (op==0)
{x=query(1,1,n);
fout<<x<<"\n";}
else update (1,1,n);
}
return 0;
}