結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-06 21:52:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 306 ms / 2,000 ms |
| コード長 | 1,677 bytes |
| コンパイル時間 | 1,781 ms |
| コンパイル使用メモリ | 176,972 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-06-24 17:38:44 |
| 合計ジャッジ時間 | 4,734 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T>
struct Segtree {
int n;
T e;
vector<T> dat;
typedef function<T(T a, T b)> Func;
Func f;
Segtree(){}
Segtree(int n_input, Func f_input, T e_input){
initialize(n_input, f_input, e_input);
}
void initialize(int n_input, Func f_input, T e_input){
f = f_input;
e = e_input;
n = 1;
while(n < n_input) n <<= 1;
dat.resize(2*n-1, e);
}
void update(int k, T a){
k += n - 1;
dat[k] = a;
while(k > 0){
k = (k - 1)/2;
dat[k] = f(dat[2*k+1], dat[2*k+2]);
}
}
T get(int k){
return dat[k+n-1];
}
T between(int a, int b){
return query(a, b+1, 0, 0, n);
}
T query(int a, int b, int k, int l, int r){
if(r<=a || b<=l) return e;
if(a<=l && r<=b) return dat[k];
T vl = query(a, b, 2*k+1, l, (l+r)/2);
T vr = query(a, b, 2*k+2, (l+r)/2, r);
return f(vl, vr);
}
};
int main(){
int N, Q;
cin >> N >> Q;
vector<int> A(N);
for(int i=0; i<N; i++) cin >> A[i];
typedef pair<int, int> P;
const P INFP = {1e9, 1e9};
Segtree<P> st(N, [](auto a, auto b){ return min(a, b);}, INFP);
for(int i=0; i<N; i++) st.update(i, {A[i], i+1});
while(Q--){
int t, l, r;
cin >> t >> l >> r;
l--; r--;
if(t == 1){
swap(A[l], A[r]);
st.update(l, {A[l], l+1});
st.update(r, {A[r], r+1});
}else{
int ans = st.between(l, r).second;
cout << ans << endl;
}
}
return 0;
}