Cod sursa(job #1414239)

Utilizator irimiecIrimie Catalin irimiec Data 2 aprilie 2015 14:17:13
Problema Arbori de intervale Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 1.97 kb
#include <bits/stdc++.h>

using namespace std;

#define     mp              make_pair
#define     fs              first
#define     sc              second
#define     pob             pop_back
#define     pub             push_back
#define     eps             1E-7
#define     sz(a)           a.size()
#define     count_one       __builtin_popcount;
#define     count_onell     __builtin_popcountll;
#define     fastIO          ios_base::sync_with_stdio(false)
#define     PI              (acos(-1.0))
#define     linf            (1LL<<62)//>4e18
#define     inf             (0x7f7f7f7f)//>2e9

const int MAXN = 100010;
#define nds (nod * 2)
#define ndr (nod * 2 + 1)

inline int maxim(int a, int b) { if(a < b) return b; return a; }

int n, m, val, st, dr, pos, maxx;
int arb[4*MAXN + 100];

void query(int nod, int l, int r) {
    if(st <= l && r <= dr) {
        if(maxx < arb[nod])
            maxx = arb[nod];
        return;
    }

    int mid = (l + r) / 2;
    if(st <= mid)
        query(nds, l, mid);
    if(mid < dr)
        query(ndr, mid + 1, r);
}

void update(int nod, int l, int r) {
    if(l == r) {
        arb[nod] = val;
        return;
    }

    int mid = (l + r) >> 1;
    if(mid >= pos)
        update(nds, l, mid);
    else
        update(ndr, mid + 1, r);
    arb[nod] = maxim(arb[nds], arb[ndr]);
}

void read() {
    #ifndef ONLINE_JUDGE
    assert(freopen("arbint.in", "r", stdin));
    assert(freopen("arbint.out", "w", stdout));
    #endif
    fastIO;
    int tip;

	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
	    cin >> val;
	    pos = i;
	    update(1, 1, n);
	}

    while(m--) {
        cin >> tip;
        if(tip == 0) {
            maxx = -1;
            cin >> st >> dr;
            query(1, 1, n);
            cout << maxx << "\n";
        }
        if(tip == 1) {
            cin >> pos >> val;
            update(1, 1, n);
        }
    }
}

int main() {
	read();

    return 0;
}