結果

問題 No.875 Range Mindex Query
ユーザー どららどらら
提出日時 2019-09-07 11:07:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 1,866 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 168,596 KB
実行使用メモリ 5,416 KB
最終ジャッジ日時 2023-09-08 13:08:40
合計ジャッジ時間 4,940 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 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,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 194 ms
5,268 KB
testcase_12 AC 157 ms
4,380 KB
testcase_13 AC 137 ms
5,092 KB
testcase_14 AC 133 ms
5,164 KB
testcase_15 AC 184 ms
5,416 KB
testcase_16 AC 241 ms
5,168 KB
testcase_17 AC 259 ms
5,192 KB
testcase_18 AC 253 ms
5,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

const static int INF = 10000000;

struct ST {
  int x, y;
  ST():x(INF),y(INF){}
  ST(int x, int y):x(x),y(y){}
};
ST combine(const ST& lhs, const ST& rhs){
  ST st;
  if(lhs.x < rhs.x){
    st = lhs;
  }else{
    st = rhs;
  }
  return st;
}
template<class S>
class SegmentTree {
  int N;
  vector<S> t;
  void build(){
    for(int i=N-1; i>0; i--){
      t[i] = combine(t[i<<1], t[i<<1|1]);
    }
  }
public:
  SegmentTree(int n_){
    N = 1;
    while(N < n_) N *= 2;
    t.resize(2*N);
    for(int i=N; i<2*N; i++){
      t[i] = S();
    }
    build();
  }
  SegmentTree(const vector<S>& v){
    N = 1;
    while(N < v.size()) N *= 2;
    t.resize(2*N);
    for(int i=0; i<v.size(); i++){
      t[i+N] = v[i];
    }
    build();
  }
  void modify(int p, S val){
    for(t[p+=N] = val; p>>=1;){
      t[p] = combine(t[p<<1], t[p<<1|1]);
    }
  }
  S query(int l, int r){
    S resl, resr;
    for(l+=N, r+=N; l<r; l>>=1, r>>=1){
      if(l&1) resl = combine(resl, t[l++]);
      if(r&1) resr = combine(t[--r], resr);
    }
    return combine(resl, resr);
  }
};


int main(){
  int N, Q;
  cin >> N >> Q;

  SegmentTree<ST> segtree(N);

  rep(i,N){
    int a;
    cin >> a;
    segtree.modify(i,ST(a,i));
  }
  rep(i,Q){
    int x, l, r;
    cin >> x >> l >> r;
    l--;
    r--;
    if(x == 1){
      ST lhs = segtree.query(l,l+1);
      ST rhs = segtree.query(r,r+1);
      swap(lhs.y, rhs.y);
      segtree.modify(l,rhs);
      segtree.modify(r,lhs);
    }else{
      ST ret = segtree.query(l,r+1);
      cout << ret.y+1 << endl;
    }
  }
  
  return 0;
}

0