Cod sursa(job #3229145)

Utilizator Sebi_RipaSebastian Ripa Sebi_Ripa Data 14 mai 2024 08:51:29
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.11 kb
#include <fstream>
#define int long long
 
using namespace std;

ifstream cin ("arbint.in");
ofstream cout ("arbint.out");
 
int st[400005];
 
void update(int to, int from, int pos, int val, int node) {
    if(to == from) {
        st[node] = val;
        return;
    }
    int mid = (from+to)/2;
    if(pos <= mid)
        update(mid, from, pos, val, node*2);
    else update(to, mid+1, pos, val, node*2+1);
    st[node] = max(st[2*node],st[2*node+1]);
}
 
int query(int from, int to, int node, int ql, int qr) {
    if(ql <= from && to <= qr)
        return st[node];
    int mid = (to+from)/2, s = 0;
    if(ql <= mid)
        s = max(s, query(from, mid, node*2, ql, qr));
    if(mid+1 <= qr)
        s = max(s, query(mid+1, to, node*2+1, ql, qr));
    return s;
}
 
signed main() {
    int n,q, x;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        cin >> x;
        update(n, 1, i, x, 1);
    }
    while(q--) {
        int cer, a, b;
        cin >> cer >> a >> b;
        if(cer == 1)
            update(n, 1, a, b, 1);
        else cout << query(1, n, 1, a, b) << '\n';
    }
}