Pagini recente » Cod sursa (job #2914773) | Cod sursa (job #2410422) | Cod sursa (job #513211) | Cod sursa (job #139113) | Cod sursa (job #857608)
Cod sursa(job #857608)
#define max(x,y) (x<y)?y:x
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int arb[400999],v[100009];
int n,m,x,y;
void init(int poz,int a,int b)
{
if (a==b) arb[poz]=v[a]; else
{
int c=(a+b)/2;
init(poz*2,a,c);
init(poz*2+1,c+1,b);
arb[poz]=max(arb[poz*2],arb[poz*2+1]);
}
}
int get(int poz, int a, int b)
{
int c=(a+b)/2;
if ((x<=a) && (y>=b)) return arb[poz];
if (y<=c) return get(poz*2,a,c);
if (x>c) return get(poz*2+1,c+1,b);
return max(get(poz*2,a,c),get(poz*2+1,c+1,b));
}
void update(int poz, int a , int b)
{
int c=(a+b)/2;
if ((a==x) && (b==x)) arb[poz]=y; else
{
if (x<=c) update(poz*2,a,c); else
update(poz*2+1,c+1,b);
arb[poz]=max(arb[poz*2],arb[poz*2+1]);
}
}
int main()
{
f>>n>>m;
for (int i=1;i<=n;++i) f>>v[i];
init(1,1,n);
for (int i=1;i<=m;++i)
{
int op;
f>>op>>x>>y;
if (op==0)
g<<get(1,1,n)<<"\n"; else
update(1,1,n);
}
return 0;
}