結果

問題 No.875 Range Mindex Query
ユーザー totori_nyaatotori_nyaa
提出日時 2019-09-06 22:54:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,626 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 166,200 KB
実行使用メモリ 11,628 KB
最終ジャッジ日時 2023-09-07 01:52:32
合計ジャッジ時間 4,123 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,472 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

void update(ll k, ll p){
    k += m-1;
    idx[k] = k - m + 1;
    dat[k] = p;
    while(k>0){
        k = (k-1)/2;
        dat[k] = min(dat[k*2 + 1], dat[k*2+2]);
        if(dat[k*2+1] < dat[k*2+2]) idx[k] = idx[k*2+1];
        else idx[k] = idx[k*2+2];
    }
}


// query(a,b,0,0,n) → [a,b)

int ans ;
ll query(ll a, ll b, ll k, ll l, ll r){
    ans = k;
    if(r<=a || b<=l) return -1;
    if(a<=l && r<=b) return idx[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        // return min(vl,vr);
        if(vl!=-1 && vr != -1){
            if(dat[vl] < dat[vr]) return vl;
            else return vr;
        }
        if(vr!=-1) return vr;
        else return vl;
    }
}

    
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,m) + 1 << endl;
            //cout << ans + 1 << endl;
        }
    }
 

    
}
0