結果

問題 No.875 Range Mindex Query
ユーザー SugarDragon5SugarDragon5
提出日時 2019-09-06 21:36:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 176,428 KB
実行使用メモリ 9,276 KB
最終ジャッジ日時 2023-09-06 22:58:44
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
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 279 ms
8,896 KB
testcase_17 AC 302 ms
9,276 KB
testcase_18 AC 290 ms
9,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
struct SegTree{
    int n;
    vector<int> v;
    SegTree(int _n){
        n=1;
        while(n<_n){
            n*=2;
        }
        v.assign(n*2+10,INT_MAX);
    }
    void set(vector<int>&vec){
        for(int i=0;i<vec.size();i++){
            v[i+n]=vec[i];
        }
        for(int i=n-1;i>0;i--){
            v[i]=min(v[i*2],v[i*2+1]);
        }
    }
    void update(int k,int x){
        k+=n;
        v[k]=x;
        k/=2;
        while(k){
            v[k]=min(v[k*2],v[k*2+1]);
            k/=2;
        }
    }
    void swap(int a,int b){
        int t=v[a+n];
        update(a,v[b+n]);
        update(b,t);
    }
    int mi(int l,int r){
        l+=n;
        r+=n;
        int ans=INT_MAX;
        while(l<r){
            if(l%2){
                ans=min(ans,v[l]);
                l++;
            }
            if(r%2){
                ans=min(ans,v[r-1]);
                r--;
            }
            l/=2;
            r/=2;
        }
        return ans;
    }
    void debug(){
        for(int i=1;i<=n*2;i++){
            cout<<v[i]<<" ";
        }
        cout<<endl;
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    SegTree tr(n);
    map<int,int> ma;
    for(int i=0;i<n;i++){
        ma[vec[i]]=i;
    }
    tr.set(vec);
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        b--;c--;
        if(a==1){
            swap(ma[vec[b]],ma[vec[c]]);
            tr.swap(b,c);
        }else{
            cout<<ma[tr.mi(b,c+1)]+1<<endl;
        }
    }
    return 0;
}
0