結果

問題 No.875 Range Mindex Query
ユーザー kk
提出日時 2020-09-05 19:28:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,726 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 210,332 KB
実行使用メモリ 6,280 KB
最終ジャッジ日時 2023-08-19 12:56:38
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 167 ms
5,364 KB
testcase_12 AC 138 ms
4,840 KB
testcase_13 AC 117 ms
5,876 KB
testcase_14 AC 113 ms
5,672 KB
testcase_15 AC 158 ms
5,824 KB
testcase_16 AC 189 ms
6,020 KB
testcase_17 AC 201 ms
6,280 KB
testcase_18 AC 197 ms
6,108 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;
  
  // irrelevant value for query
  const T NIL = {1<<30, -1};
  
  // binary operator for query
  T binop(T a, T b) {
    return min(a, b);
  }
  
  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];
    else {
      T ret = NIL;
      ret = binop(ret, query(2*k+1, l, (l+r)/2, a, b));
      ret = binop(ret, query(2*k+2, (l+r)/2, r, a, b));
      return ret;
    }
  }
public:
  SegTree(int n): n(n), seg(4*n) {}
  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);
  }
};

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

  int n, q;
  cin >> n >> q;
  SegTree<pair<int, int> > tree(n);
  
  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