Cod sursa(job #3375245)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 11 noiembrie 2026 10:30:51
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.94 kb
// https://www.infoarena.ro/problema/arbint

#pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC optimize("O3,unroll-loops")
#pragma GCC target(                                                            \
    "avx512f,avx512bw,avx512dq,avx512cd,avx512vl,bmi,bmi2,lzcnt,popcnt,fma")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")

// #define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

using int64 = int64_t;
using uint64 = uint64_t;
using int32 = int32_t;
using uint32 = uint32_t;
using int16 = int16_t;
using uint16 = uint16_t;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define all(x) (x).begin(), (x).end()
#define allg(x) (x).begin(), (x).end(), greater<int>()
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rfor(i, st, dr) for (auto i = (st); i <= (dr); ++i)
#define for0(i, n) for (auto i = 0; i < (n); ++i)
#define rfor0(i, n) for (auto i = (n) - 1; i >= 0; --i)
#define for1(i, n) for (auto i = 1; i <= (n); ++i)
#define rfor1(i, n) for (auto i = (n); i >= 1; --i)
#define foreach(x, a) for (auto &x : a)
#define cforeach(x, a) for (const auto &x : a)
#define ft first
#define sd second
#define cendl cout << "\n"
#define fendl fout << "\n"
#define FASTIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);

// #define int int64

ifstream fin("arbint.in");
ofstream fout("arbint.out");

// FILE* fin = fopen("", "r");
// FILE* fout = fopen("", "w");

const int NRMAX = 100000;

int v[NRMAX], arb[2 * NRMAX];

int query(int x, int st, int dr, int a, int b) {
  if (a <= st && dr <= b) {
    return arb[x];
  }

  int m = (st + dr) / 2;
  int ls = x + 1;
  int rs = x + 2 * (m - st + 1);
  int rez = 0;

  if (a <= m)
    rez = max(rez, query(ls, st, m, a, b));
  if (b > m)
    rez = max(rez, query(rs, m + 1, dr, a, b));

  return rez;
}

void update(int x, int st, int dr, int a, int b) {
  if (st == dr) {
    arb[x] = b;
    return;
  }

  int m = (st + dr) / 2;
  int ls = x + 1;
  int rs = x + 2 * (m - st + 1);

  if (a <= m)
    update(ls, st, m, a, b);
  else
    update(rs, m + 1, dr, a, b);

  arb[x] = max(arb[ls], arb[rs]);
}

void build(int x, int st, int dr) {
  if (st == dr) {
    arb[x] = v[st];
    return;
  }

  int m = (st + dr) / 2;
  int ls = x + 1;
  int rs = x + 2 * (m - st + 1);

  build(ls, st, m);
  build(rs, m + 1, dr);

  arb[x] = max(arb[ls], arb[rs]);
}

int main() {
  int n, m, i, op, a, b;

  fin >> n >> m;

  for (i = 0; i < n; ++i) {

    fin >> v[i];
  }

  build(0, 0, n - 1);

  while (m--) {
    fin >> op >> a >> b;
    --a;
    if (op == 0) { // query
      --b;
      fout << query(0, 0, n - 1, a, b) << "\n";
    } else { // update
      update(0, 0, n - 1, a, b);
    }
  }

  return 0;
}