Pagini recente » Cod sursa (job #2288436) | Cod sursa (job #1834748) | Cod sursa (job #2701246) | Cod sursa (job #2684807) | Cod sursa (job #3246440)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int NMAX = 100001;
int n, m;
///AINT
int T[4 * NMAX], v[NMAX];
void build_tree()
{
for(int i = 1; i <= n; i++)
T[i + n] = v[i];
for(int i = n; i >= 1; i--)
T[i] = max(T[i * 2], T[i * 2 + 1]);
}
void update(int poz, int val)
{
poz += n;
T[poz] = val;
while(poz > 1)
{
poz /= 2;
T[poz] = max(T[poz * 2], T[poz * 2 + 1]);
}
}
int query(int st, int dr)
{
int maxx = 0;
st += n;
dr += n;
while(st <= dr)
{
if(st % 2 != 0) ///fiu drept,obligat sa includ
maxx = max(maxx, T[st++]);
st /= 2;
///
if(dr % 2 == 0) ///fiu stang,obligat sa includ
maxx = max(maxx, T[dr--]);
dr /= 2;
}
return maxx;
}
///
void AproxN()
{
while (n & (n - 1))
n += n & -n;
n--;
}
void Read()
{
int x;
f >> n >> m;
for(int i = 1; i <= n; i++)
f >> v[i];
}
void ProcessQueries()
{
int x, y, tip;
for(int i = 1; i <= m; i++)
{
f >> tip >> x >> y;
if(tip == 0)
g << query(x, y) << '\n';
else
update(x, y);
}
}
int main()
{
Read();
AproxN();
build_tree();
ProcessQueries();
return 0;
}