結果

問題 No.875 Range Mindex Query
ユーザー yuji9511yuji9511
提出日時 2019-09-06 21:29:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,864 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 162,636 KB
実行使用メモリ 6,992 KB
最終ジャッジ日時 2023-09-06 22:36:15
合計ジャッジ時間 4,659 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,780 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 4 ms
6,808 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 215 ms
6,804 KB
testcase_17 AC 236 ms
6,808 KB
testcase_18 AC 226 ms
6,732 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;
    while(Q--){
        ll n, l, r;
        cin >> n >> l >> r;
        l--; r--;
        if(n == 1){
            ll tt = pos[v[l]];
            pos[v[l]] = pos[v[r]];
            pos[v[r]] = tt;
            ll tmp = v[l];
            sg.update(l, v[r]);
            sg.update(r, tmp);
        }else{
            ll val = sg.getMin(l, r+1);
            print(pos[val] + 1);
        }
    }

}
0