Cod sursa(job #1361814)

Utilizator viuscenkoViktor Iuscenko viuscenko Data 25 februarie 2015 23:53:43
Problema Arbori de intervale Scor 0
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

#define DEBUG 1
#ifdef DEBUG
#define D(x) x
#else
#define D(x)
#endif
#define MAXN 100000

FILE *in = fopen("arbint.in", "r");
FILE *out = fopen("arbint.out", "w");

int m, n, x, pos, Start, End, maxim;

inline int maxx(int a, int b) { if(a > b) return a; return b; }
int aint[4*MAXN + 100];

void update(int nod, int l, int r) {
    if(l == r) {
        aint[nod] = x;
        return;
    } else {
        int mid = l + (r - l)/2;
        if(pos <= mid)  update(2*nod, l, mid);
        else            update(2*nod+1, mid+1, r);

        aint[nod] = maxx(aint[2*nod], aint[2*nod+1]);
    }
}

void query(int nod, int l, int r) {
    if(Start <= l && r <= End) {
        if(maxim < aint[nod])
            maxim = aint[nod];
        return;
    }

    int mid = l + (r-l)/2;
    if(Start <= mid)    query(2*nod, l, mid);
    if(mid < End)       query(2*nod+1, mid+1, r);
}

int main()
{
    fscanf(in, "%d%d", &m, &n);

    for(int i = 1; i <= n; ++i) {
        fscanf(in, "%d", &x);

        pos = i;
        update(1, 1, n);
    }

    int type;
    while(m--) {
        fscanf(in, "%d%d%d", &type, &pos, &x);
        if(type == 0) {
            Start = pos; End = x;
            maxim = -1;
            query(1, 1, n);
            fprintf(out, "%d\n", maxim);
        } else {
            update(1, 1, n);
        }
    }

    return 0;
}