Cod sursa(job #1156198)

Utilizator cbanu96Banu Cristian cbanu96 Data 27 martie 2014 15:00:38
Problema Arbori de intervale Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 1.37 kb
#include <cstdio>
#include <algorithm>

using namespace std;

#define FILEIN "arbint.in"
#define FILEOUT "arbint.out"
#define NMAX 100005

int ArbInt[262145];
int N, M, q;
int pos, val, a, b;

#define UPDATE(x, y, z, t, v) \
        pos = (t), val = (v), update((x),(y),(z))

#define QUERY(x, y, z, t, v) \
        a = (t), b = (v), query((x),(y),(z))

inline void update(int nod, int l, int r) {
    if ( l == r ) {
        ArbInt[nod] = val;
    } else {
        int m = (l+r)/2;
        if (pos <= m) {
            update(nod * 2, l, m);
        } else {
            update(nod * 2 + 1, m+1, r);
        }

        ArbInt[nod] = max(ArbInt[nod*2], ArbInt[nod*2+1]);
    }
}

inline void query(int nod, int l, int r) {
    if (a <= l && r <= b) {
        q = max(q, ArbInt[nod]);
        return;
    }

    int m = (l+r)/2;
    if (a <= m) {
        query(2*nod, l, m);
    }
    if (m < b) {
        query(2*nod+1, m+1, r);
    }
}

int main() {
    freopen(FILEIN, "r", stdin);
    freopen(FILEOUT, "w", stdout);

    scanf("%d %d", &N, &M);
    for ( int i = 1, x; i <= N; i++ ) {
        scanf("%d", &x);
        UPDATE(1, 1, N, i, x);
    }

    for ( int i = 1, x, y, z; i <= M; i++ ) {
        scanf("%d %d %d", &x, &y, &z);
        if (x) {
            UPDATE(1,1,N, y, z);
        } else {
            q = 0; QUERY(1, 1, N, y, z);
            printf("%d\n", q);
        }
    }

    return 0;
}