結果

問題 No.875 Range Mindex Query
ユーザー oxyshoweroxyshower
提出日時 2020-01-23 13:40:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 1,838 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 174,964 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-09-26 10:30:11
合計ジャッジ時間 5,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 255 ms
9,476 KB
testcase_12 AC 212 ms
6,700 KB
testcase_13 AC 177 ms
10,064 KB
testcase_14 AC 174 ms
9,852 KB
testcase_15 AC 239 ms
10,080 KB
testcase_16 AC 280 ms
10,112 KB
testcase_17 AC 299 ms
10,060 KB
testcase_18 AC 290 ms
10,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(){}
  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  void print(){
    for(int i = 0; i < n; i++){
      cout << node[i+n-1] << " ";
    }
    cout << endl;
  }
};
using P = pair<int, int>;

signed main(){

  int n, q; cin >> n >> q;
  vector<P> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i].first;
    a[i].second = i+1;
  }

  SegmentTree<P> seg(a,P(INF, INF),[&](P x, P y){ return min(x, y); });
  for(int i = 0; i < q; i++){
    int c, l, r; cin >> c >> l >> r;
    l--, r--;
    if(c == 1){
      P p = seg.getval(l, l+1), q = seg.getval(r, r+1);
      swap(p.second, q.second);
      seg.update(l, q);
      seg.update(r, p);
    }else{
      cout << seg.getval(l, r+1).second << endl;
    }
  }

  return 0;
}
0