Pagini recente » Cod sursa (job #194770) | Cod sursa (job #62085) | Autentificare | Cod sursa (job #1554085) | Cod sursa (job #1154639)
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout("arbint.out");
#define MAX 100010
FILE *fin=fopen("arbint.in", "r");
unsigned const maxb=8192;
char buf[maxb];
int ptr=maxb-1;
int getInt()
{
int nr=0;
while(buf[ptr]>'9' || buf[ptr]<'0')
{
if(++ptr>=maxb)
fread(buf, maxb, 1, fin), ptr=0;
}
while(buf[ptr]<='9' && buf[ptr]>='0')
{
nr=nr*10+buf[ptr]-'0';
if(++ptr>=maxb)
fread(buf, maxb, 1, fin), ptr=0;
}
return nr;
}
int a[4*MAX];
//se citeste un sir de numere si doua tipuri de operatii
//0 x y
//val de pe poz x devine y
//1 x y
//afisati maximul din intervalul (x, y)
int Pos, Val, start, end_the_variable;
void Update(int nod, int st, int dr)
{
if(st==dr)
{
a[nod]=Val;
return;
}
int ma=st+dr;
ma>>=1;
if(Pos<=ma)
Update(2*nod, st, ma);
else
Update(2*nod+1, ma+1, dr);
a[nod]=max(a[nod*2], a[nod*2+1]);
}
int Query(int nod, int st, int dr)
{
if(start<=st && dr<=end_the_variable)
{
return a[nod];
}
if(end_the_variable<st || dr<start)
{
return -1;
}
int ma=(st+dr)>>1;
return max(Query(2*nod, st, ma), Query(2*nod+1, ma+1, dr));
}
int main()
{
int n, m;
n=getInt();
m=getInt();
int i, x, b, y;
for(i=1;i<=n;i++)
{
x=getInt();
Pos=i;
Val=x;
Update(1, 1, n);
}
while(m--)
{
b=getInt();
x=getInt();
y=getInt();
if(b==1)
{
Pos=x;
Val=y;
Update(1, 1, n);
}
else
{
start=x;
end_the_variable=y;
fout<<Query(1, 1, n)<<"\n";
}
}
return 0;
}