Pagini recente » Borderou de evaluare (job #3012917) | Borderou de evaluare (job #2204814) | Borderou de evaluare (job #3251840) | Borderou de evaluare (job #3252095) | Cod sursa (job #3316246)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int n, m, a[300005], p, t, x, y;
int maxim (int stq, int drq, int stn, int drn, int indn) {
if (stq <= stn && drq >= drn)
return a[indn];
int ma = 0;
if (stq <= (stn + drn)/2)
ma = maxim (stq, drq, stn, (stn+drn)/2, indn*2);
if (drq > (stn + drn)/2)
ma = max(ma, maxim (stq, drq, (stn+drn)/2 + 1, drn, indn*2+1));
return ma;
}
void update (int poz, int val) {
a[poz] = val;
while (poz >= 1) {
poz /= 2;
a[poz] = max (a[poz*2], a[poz*2+1]);
}
}
int main()
{
f >> n >> m;
p = 1;
while (p < n)
p *= 2;
for (int i=1; i<=n; ++i)
f >> a[p+i-1];
for (int i=p-1; i>=1; --i)
a[i] = max (a[i*2], a[i*2+1]);
for (int i=1; i<=m; ++i) {
f >> t >> x >> y;
if (t == 0)
g << maxim (x, y, 1, p, 1) << '\n';
else
update (x+p-1, y);
}
return 0;
}