Cod sursa(job #2329857)

Utilizator StefanZamfirStefan Zamfir StefanZamfir Data 27 ianuarie 2019 16:10:33
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.61 kb

/*


      _             _    ___     ___    _  __       __
   __| |   __ _    / |  / _ \   / _ \  (_)/ /    _  \ \
  / _` |  / _` |   | | | | | | | | | |   / /    (_)  | |
 | (_| | | (_| |   | | | |_| | | |_| |  / /_     _   | |
  \__,_|  \__,_|   |_|  \___/   \___/  /_/(_)   (_)  | |
                                                    /_/


 */

//#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#include <algorithm>
#include <bitset>
#include <time.h>
#include <tuple>
#include <fstream>
#include <iomanip>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>

#pragma warning "da 100% din tine. :)"
#define nl '\n'
#define cnl cout << '\n';
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ll long long
#define ull unsigned ll
#ifdef INFOARENA
#define ProblemName "arbint"
#endif
#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "a.in"
#define OuFile "a.out"
#endif


//using namespace __gnu_pbds;
using namespace std;
ifstream cin(InFile);
ofstream cout(OuFile);


//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

template<class v, class type>
void print(v Vector, type nr) {
    for_each(all(Vector), [](type x) {
        cout << x << ' ';
    });
}

int n, q;
int tree[400001];

inline void update(int nod, int st, int dr, int pos, int val) {
    if (st == dr)
        tree[nod] = val;
    else {
        int mid = (st + dr) >> 1;
        if (pos <= mid) update(2 * nod, st, mid, pos, val);
        else            update(2 * nod + 1, mid + 1, dr, pos, val);
        tree[nod] = max(tree[2 * nod], tree[2 * nod + 1]);
    }
}

inline void query(int nod, int st, int dr, int a, int b, int &mx) {
    if (st >= a && dr <= b)
        mx = max(mx, tree[nod]);
    else {
        int mid = (st + dr) >> 1;
        if (a <= mid) query(2 * nod, st, mid, a, b, mx);
        if (b > mid)  query(2 * nod + 1, mid + 1, dr, a, b, mx);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    clock_t tStart = clock();
    int val;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> val;
        update(1, 1, n, i + 1, val);
    }
    int op, a, b, mx;
    while (q--) {
        cin >> op >> a >> b;
        if (!op) {
            mx = -2;
            query(1, 1, n, a, b, mx);
            cout << mx << nl;
        } else update(1, 1, n, a, b);
    }
    printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}