Cod sursa(job #2984604)

Utilizator sebuxSebastian sebux Data 24 februarie 2023 15:33:15
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.77 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

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

typedef unsigned long long ull;


void getint(int& x) {
    char c;
    while (cin.get(c) && !cin.eof() && isspace(c));
    if (cin.eof()) return;
    x = c - '0';
    while (cin.get(c) && !cin.eof() && isdigit(c)) x = x * 10 + (c - '0');
}

const int sze = 1e5;
int tree[4 * sze + 1];
void buildAint(int n, int st, int dr) {
    if (st == dr) {
        cin >> tree[n];
        return;
    }
    int mij = (st + dr) / 2;
    buildAint(2 * n, st, mij);
    buildAint(2 * n + 1, mij + 1, dr);
    tree[n] = max(tree[2 * n], tree[2 * n + 1]);
}

void updateAint(int n, int st, int dr, int pos, int val) {
    if (st == dr) {
        tree[n] = val;
        return;
    }
    int mij = (st + dr) / 2;
    if (pos <= mij) updateAint(2 * n, st, mij, pos, val);
    else updateAint(2 * n + 1, mij + 1, dr, pos, val);
    tree[n] = max(tree[2 * n], tree[2 * n + 1]);
}

int queryAint(int n, int st, int dr, int a, int b) {
    if (a <= st && dr <= b) return tree[n];
    int mij = (st + dr) / 2;
    int s = 0, d = 0;
    if (a <= mij) s = queryAint(2 * n, st, mij, a, b);
    if (b > mij) d = queryAint(2 * n + 1, mij + 1, dr, a, b);
    return max(s, d);
}




int main() {
    int n, m;
    cin >> n >> m;
    buildAint(1, 1, n);
    int op, x, y;
    while (m--) {
        cin >> op >> x >> y;
        if (op == 0) {
            cout << queryAint(1, 1, n, x, y) << "\n";
        }
        else {
            updateAint(1, 1, n, x, y);
        }
    }


    
    return 0;
}