結果

問題 No.875 Range Mindex Query
ユーザー risujirohrisujiroh
提出日時 2019-09-06 21:24:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 1,523 ms
コンパイル使用メモリ 169,092 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-09-06 22:06:54
合計ジャッジ時間 3,353 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 58 ms
4,384 KB
testcase_12 AC 47 ms
4,384 KB
testcase_13 AC 42 ms
4,688 KB
testcase_14 AC 40 ms
4,536 KB
testcase_15 AC 54 ms
4,596 KB
testcase_16 AC 59 ms
4,692 KB
testcase_17 AC 61 ms
4,664 KB
testcase_18 AC 57 ms
4,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using T = pair<int, int>;
  static T op(const T& a, const T& b) { return min(a, b); }
  static constexpr T e() { return {2e9, -1}; }

  const int n;
  V<T> t;
  SegmentTree(int n) : n(n), t(2 * n, e()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  T acc(int l, int r) const {
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  void set(int i, const T& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  SegmentTree st(n);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    st[i] = {a, i};
  }
  st.build();

  while (q--) {
    int tp; cin >> tp;
    if (tp == 1) {
      int l, r; cin >> l >> r, --l, --r;
      int vl = st[l].first, vr = st[r].first;
      st.set(l, {vr, l});
      st.set(r, {vl, r});
    } else {
      int l, r; cin >> l >> r, --l;
      cout << st.acc(l, r).second + 1 << '\n';
    }
  }
}
0