結果

問題 No.875 Range Mindex Query
ユーザー kk
提出日時 2020-09-05 18:56:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 201,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 12:46:50
合計ジャッジ時間 6,375 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 3 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 193 ms
4,380 KB
testcase_12 AC 160 ms
4,380 KB
testcase_13 AC 126 ms
4,384 KB
testcase_14 AC 125 ms
4,380 KB
testcase_15 AC 176 ms
4,380 KB
testcase_16 AC 265 ms
4,380 KB
testcase_17 AC 288 ms
4,380 KB
testcase_18 AC 278 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

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

  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  REP (i, n) cin >> a[i];
  vector<int> bucket(333, -1);

  REP (i, n) {
    int j = i/333;
    if (bucket[j] == -1 || a[bucket[j]] > a[i])
      bucket[j] = i;
  }
  
  while (q--) {
    int type, l, r;
    cin >> type >> l >> r;
    if (type == 1) {
      --l, --r;
      swap(a[l], a[r]);
      for (int x : { l, r }) {
        int j = x/333;
        for (int i = j * 333; i < (j + 1) * 333; i++) {
          if (a[i] < a[bucket[j]])
            bucket[j] = i;
        }
      }
    } else {
      --l;
      int p = -1;
      while (l < r && l % 333) {
        if (p == -1 || a[l] < a[p]) p = l;
        ++l;
      }
      while (l + 333 <= r) {
        if (p == -1 || a[bucket[l/333]] < a[p]) p = bucket[l/333];
        l += 333;
      }
      while (l < r) {
        if (p == -1 || a[l] < a[p]) p = l;
        ++l;
      }
      cout << p+1 << endl;
    }
  }
  
  return 0;
}
0