Cod sursa(job #2205702)

Utilizator ContDeRacistAliniateEBlat ContDeRacist Data 19 mai 2018 22:38:04
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <fstream>

using namespace std;

ifstream cin("arbint.in");
ofstream cout("arbint.out");

int t[200000];

int main()
{
    int n, m, x, y, poz, val, op;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> t[n + i];
    }
    for (int i = n - 1; i > 0; --i) {
        t[i] = max(t[i<<1], t[i<<1|1]);
    }
    poz = n;
    val = 1;
    for (; poz > 1; poz>>=1) {
        t[poz>>1] = t[poz] + t[poz^1];
    }
    for (int i = 0; i < m; ++i) {
        cin >> op;
        if (op) {
            cin >> poz >> val;
            --poz;
            poz += n;
            t[poz] = val;
            for (; poz > 1; poz >>= 1) {
                t[poz>>1] = max(t[poz], t[poz^1]);
            }
        }
        else {
            int ans(0);
            cin >> x >> y;
            --x;
            x += n;
            y += n;
            for (; x < y; x>>=1, y>>=1) {
                if (x&1) {
                    ans = max(ans, t[x++]);
                }
                if (y&1) {
                    ans = max(ans, t[y--]);
                }
            }
            cout << ans << "\n";
        }
    }
    return 0;
}