Submission details
Task:Dynamic Range Minimum Queries
Sender:discape
Submission time:2025-09-24 14:43:25 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.46 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
// clang-format off
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { T value; is >> value; v.push_back(value); return is; }
#define preamble ios::sync_with_stdio(0); cin.tie(0); dbg("INIT");
// clang-format on
#ifdef DO_DBG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template <typename T> using v = vector<T>;
template <typename T> using us = unordered_set<T>;
template <typename K, typename V> using um = unordered_map<K, V>;
constexpr int MOD = 1e9 + 7;
constexpr const int INF = 1e9;
const ld EPS = 1e-9;
#define loopi(n) for (int i = 0; i < n; i++)
#define loopj(n) for (int j = 0; j < n; j++)
#define loopk(n) for (int k = 0; k < n; k++)
#define loopz(n) for (int z = 0; z < n; z++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sq(x) ((x) * (x))

ull p2(ull k) {
  // Let p2(k) denote the smallest power of 2 geq k
  ull i = 1;
  while (i < k)
    i *= 2;
  return i;
}

int main() {
  int n, q;
  cin >> n >> q;
  v<int> x;
  loopz(n) cin >> x;
  ull tsize = 2 * p2(n);
  v<ull> tree(tsize, INF);

  // initialize the segment tree
  loopi(n) { tree[i + n] = x[i]; }
  loopi(n) {
    int idx = n - i - 1;
    tree[idx] = min(tree[2 * idx], tree[2 * idx + 1]);
  }
  dbg(tree);

  loopz(q) {
    int t, a, b;
    cin >> t >> a >> b;
    if (t == 1) {
      a--;
      a += n;
      tree[a] = b;
      a /= 2;
      while (a >= 1) {
        tree[a] = min(tree[2 * a], tree[2 * a + 1]);
        a /= 2;
      }
    } else {
      a--;
      b--;
      a += n;
      b += n;
      ull m = INF;
      while (a <= b) {
        if (a % 2 == 1)
          m = min(m, tree[a++]);
        if (b % 2 == 0)
          m = min(m, tree[b--]);
        a /= 2;
        b /= 2;
      }
      cout << m << "\n";
    }
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
8 80
7 6 4 6 2 9 4 8
2 1 1
2 1 2
2 1 3
...

correct output
7
6
4
4
2
...

user output
7
6
4
4
2
...
Truncated

Test 2

Verdict: ACCEPTED

input
200000 200000
398739055 65343131 699208332 3...

correct output
28609
129890
20378
20378
311522
...

user output
28609
129890
20378
20378
311522
...
Truncated