結果

問題 No.875 Range Mindex Query
ユーザー tonetone
提出日時 2019-09-18 13:57:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 80,304 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-09-22 10:27:52
合計ジャッジ時間 3,522 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 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 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 187 ms
4,408 KB
testcase_12 AC 153 ms
4,376 KB
testcase_13 AC 131 ms
4,500 KB
testcase_14 AC 128 ms
4,464 KB
testcase_15 AC 176 ms
4,424 KB
testcase_16 AC 256 ms
4,744 KB
testcase_17 AC 276 ms
4,468 KB
testcase_18 AC 264 ms
4,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

//-------------------------------------------------------------------
int M=1, INF=1000000007;
std::vector<int> idx(100001, -1);
std::vector<int> seg;
void init(int N){
  while(M<N) M*=2;
  M=M*2-1;
  for(int i=0;i<M;i++) {
    seg.push_back(INF);
  }
}
void update(int l, int r, int x, int k){
  k+=(M+1)/2-1;
  seg[k] = x;
  while(k>0){
    k = (k-1)/2;
    seg[k] = min(seg[k*2+1], seg[k*2+2]);
  }
}
ll query(int a, int b, int l, int r, int k){
  if(r<=a || b<=l) return INF;
  if(a<=l && r<=b) return seg[k];
  ll A = query(a, b, l, (l+r)/2, k*2+1);
  ll B = query(a, b, (l+r)/2, r, k*2+2);
  return min(A, B);
}
//-------------------------------------------------------------------

int main(int argc, char const *argv[]) {
  int N, Q, a, b, c;
  std::cin >> N >> Q;
  init(N+1);
  for(int i=0;i<N;i++){
    std::cin >> a;
    idx[a] = i+1;
    update(0, (M+1)/2, a, i);
  }
  for(int i=0;i<Q;i++){
    std::cin >> a >> b >> c;
    b--,c--;
    if(a==1){
      int tmp = seg[b+(M+1)/2-1], tmpidx=idx[seg[b+(M+1)/2-1]];
      int tmp2 = seg[c+(M+1)/2-1], tmpidx2=idx[seg[c+(M+1)/2-1]];
      idx[tmp] = tmpidx2, idx[tmp2] = tmpidx;
      update(0, (M+1)/2, tmp2, b), update(0, (M+1)/2, tmp, c);
    }else {
      std::cout << idx[query(b, c+1, 0, (M+1)/2, 0)] << '\n';
    }
  }
  return 0;
}
0