結果

問題 No.875 Range Mindex Query
ユーザー yuji9511yuji9511
提出日時 2019-09-06 21:36:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 162,168 KB
実行使用メモリ 6,908 KB
最終ジャッジ日時 2023-09-06 22:59:07
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,684 KB
testcase_01 AC 6 ms
6,692 KB
testcase_02 AC 6 ms
6,692 KB
testcase_03 AC 5 ms
6,756 KB
testcase_04 AC 5 ms
6,904 KB
testcase_05 AC 5 ms
6,704 KB
testcase_06 AC 6 ms
6,680 KB
testcase_07 AC 6 ms
6,808 KB
testcase_08 AC 5 ms
6,792 KB
testcase_09 AC 5 ms
6,700 KB
testcase_10 AC 6 ms
6,812 KB
testcase_11 AC 147 ms
6,808 KB
testcase_12 AC 118 ms
6,812 KB
testcase_13 AC 101 ms
6,808 KB
testcase_14 AC 99 ms
6,700 KB
testcase_15 AC 136 ms
6,684 KB
testcase_16 AC 214 ms
6,908 KB
testcase_17 AC 233 ms
6,688 KB
testcase_18 AC 225 ms
6,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct SegmentTree {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v){
        ll sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);

        rep(i,0,sz) node[i+n-1] = v[i];
        rrep(i,n-2,0) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(ll x, ll val){
        x += (n-1);
        node[x] = val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    ll getMin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = getMin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getMin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    vector<ll> v(100010);
    rep(i,0,N) cin >> v[i];
    SegmentTree sg(v);
    ll pos[100010] = {};
    rep(i,0,N) pos[v[i]] = i+1;
    while(Q--){
        ll n, l, r;
        cin >> n >> l >> r;
        l--; r--;
        if(n == 1){
            swap(pos[v[r]], pos[v[l]]);
            sg.update(l, v[r]);
            sg.update(r, v[l]);
            swap(v[r], v[l]);
        }else{
            ll val = sg.getMin(l, r+1);
            print(pos[val]);
        }
    }

}
0