結果

問題 No.875 Range Mindex Query
ユーザー pekempeypekempey
提出日時 2019-09-06 21:24:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 167,160 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-09-06 22:05:38
合計ジャッジ時間 3,703 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 68 ms
4,732 KB
testcase_12 AC 57 ms
4,380 KB
testcase_13 AC 52 ms
4,888 KB
testcase_14 AC 52 ms
4,836 KB
testcase_15 AC 67 ms
5,008 KB
testcase_16 AC 65 ms
4,792 KB
testcase_17 AC 70 ms
5,008 KB
testcase_18 AC 68 ms
4,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

constexpr int U = 1 << 17;
pair<int, int> dat[U * 2];

void update(int k, int v) {
  dat[k + U] = make_pair(v, k);
  k += U;
  while (k > 1) {
    k >>= 1;
    dat[k] = min(dat[k * 2], dat[k * 2 + 1]);
  }
}

pair<int, int> query(int l, int r) {
  l += U;
  r += U;
  pair<int, int> res(1e9, 1e9);
  while (l <= r) {
    if ((l & 1) == 1) res = min(res, dat[l++]);
    if ((r & 1) == 0) res = min(res, dat[r--]);
    l >>= 1;
    r >>= 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q; cin >> N >> Q;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    update(i, A[i]);
  }
  while (Q--) {
    int type; cin >> type;
    if (type == 1) {
      int l, r; cin >> l >> r; l--; r--;
      swap(A[l], A[r]);
      update(l, A[l]);
      update(r, A[r]);
    } else {
      int l, r; cin >> l >> r; l--; r--;
      cout << query(l, r).second + 1 << '\n';
    }
  }
}
0