結果

問題 No.875 Range Mindex Query
ユーザー totori_nyaatotori_nyaa
提出日時 2019-09-06 23:05:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 167,036 KB
実行使用メモリ 9,572 KB
最終ジャッジ日時 2023-09-07 02:19:51
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 154 ms
9,216 KB
testcase_12 AC 126 ms
7,064 KB
testcase_13 AC 107 ms
9,460 KB
testcase_14 AC 104 ms
9,348 KB
testcase_15 AC 145 ms
9,524 KB
testcase_16 AC 204 ms
9,572 KB
testcase_17 AC 222 ms
9,380 KB
testcase_18 AC 215 ms
9,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll INF = 1e9+7;
ll N;
pair<ll,ll> dat[2222222];
ll a[111111];

void init(ll k){
    N = 1;
    while(N < k) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = make_pair(INF,i);
}

void update(ll k, ll p){
    k += N-1;
    dat[k] = make_pair(p,k-N+1);
    while(k>0){
        k = (k-1)/2;
        if(dat[2*k+1].first < dat[2*k+2].first){
            dat[k] = dat[k*2 + 1];
        }
        else dat[k] = dat[k*2+2];

    }
}


// query(a,b,0,0,n) → [a,b)
pair<ll,ll> query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return make_pair(INF,-1);
    if(a<=l && r<=b) return dat[k];
    else{
        pair<ll,ll> vl = query(a,b,k*2+1,l,(l+r)/2);
        pair<ll,ll> vr = query(a,b,k*2+2,(l+r)/2,r);
        if(vl.first < vr.first) return vl;
        else return vr;

    }
}

    
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
 
    ll n,q;
    cin>>n>>q;
    init(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        update(i,a[i]);
    }

    while(q--){
        int p,l,r;
        cin>>p>>l>>r;
        if(p==1){
            l--,r--;
            ll tmp = a[l];
            update(l,a[r]);
            update(r,tmp);
            a[l] = a[r];
            a[r] = tmp;
        }
        else{
            l--;
            //query(l,r,0,0,m);
            cout << query(l,r,0,0,N).second + 1 << endl;
            //cout << ans + 1 << endl;
        }
    }
 

    
}
0