結果

問題 No.875 Range Mindex Query
ユーザー kk
提出日時 2020-09-05 19:44:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,639 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 207,888 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-08-19 12:57:40
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 174 ms
5,424 KB
testcase_12 AC 149 ms
4,960 KB
testcase_13 AC 119 ms
5,968 KB
testcase_14 AC 118 ms
5,652 KB
testcase_15 AC 164 ms
6,216 KB
testcase_16 AC 192 ms
5,884 KB
testcase_17 AC 217 ms
6,172 KB
testcase_18 AC 200 ms
6,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

template<typename T>
class SegTree {
  int n;
  vector<T> seg;
  T nil;
  function<T(T,T)> binop;
  
  void update(int k, int l, int r, int p, T x) {
    if (p < l || r <= p) return;
    if (r - l == 1) seg[k] = x;
    else {
      update(2*k+1, l, (l+r)/2, p, x);
      update(2*k+2, (l+r)/2, r, p, x);
      seg[k] = binop(seg[2*k+1], seg[2*k+2]);
    }
  }
  T query(int k, int l, int r, int a, int b) {
    if (b <= l || r <= a) return nil;
    if (a <= l && r <= b) return seg[k];
    return binop(query(2*k+1, l, (l+r)/2, a, b), query(2*k+2, (l+r)/2, r, a, b));
  }
public:
  SegTree(int n, T nil, function<T(T, T)> binop): n(n), seg(4*n), nil(nil), binop(binop) {}
  void init() {
    for (int i = 0; i < 4*n; i++)
      seg[i] = nil;
  }
  // update p-th value to x
  void update(int p, T x) {
    update(0, 0, n, p, x);
  }
  // query for range [l, r)
  T query(int l, int r) {
    return query(0, 0, n, l, r);
  }
};

const int INF = 1<<30;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;
  SegTree<pair<int, int> > tree(n, {INF, -1}, [](auto a, auto b) { return min(a, b); });
  
  REP (i, n) {
    int a;
    cin >> a;
    tree.update(i, {a, i});
  }

  while (q--) {
    int type, l, r;
    cin >> type >> l >> r;
    if (type == 1) {
      --l, --r;
      int lv = tree.query(l, l+1).first;
      int rv = tree.query(r, r+1).first;
      tree.update(l, {rv, l});
      tree.update(r, {lv, r});
    } else {
      cout << tree.query(--l, r).second + 1 << endl;
    }
  }
  
  return 0;
}
0