Pagini recente » Cod sursa (job #991447) | Cod sursa (job #914895) | Cod sursa (job #1337520) | Cod sursa (job #392144) | Cod sursa (job #2549943)
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1e5 + 5;
int n, q;
class SegTree
{
int a[Nmax<<1];
public:
void read()
{
int i;
for(i=0; i<n; ++i) cin >> a[i+n];
for(i=n-1; i; --i) a[i] = max(a[i<<1], a[i<<1|1]);
}
void update(int pos, int val)
{
pos += n-1;
a[pos] = val;
for(pos>>=1; pos; pos>>=1)
a[pos] = max(a[pos<<1], a[pos<<1|1]);
}
int query(int L, int R)
{
L += n-1; R += n;
int ans = 0;
for(; L < R; L>>=1, R>>=1)
{
if(L&1) ans = max(ans, a[L++]);
if(R&1) ans = max(ans, a[--R]);
}
return ans;
}
} aint;
int main()
{
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
cin.sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
aint.read();
while(q--)
{
int tip, x, y;
cin >> tip >> x >> y;
if(tip == 0)
cout << aint.query(x, y) << '\n';
else aint.update(x, y);
}
return 0;
}