結果

問題 No.875 Range Mindex Query
ユーザー ゆきのんゆきのん
提出日時 2020-03-12 02:59:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,776 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 177,724 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 22:17:47
合計ジャッジ時間 4,243 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 203 ms
6,944 KB
testcase_12 AC 168 ms
6,940 KB
testcase_13 AC 144 ms
6,944 KB
testcase_14 AC 138 ms
6,940 KB
testcase_15 AC 196 ms
6,944 KB
testcase_16 AC 243 ms
6,940 KB
testcase_17 AC 278 ms
6,944 KB
testcase_18 AC 253 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


template<class T>
struct SegmentTree{
private:
    int n;
    vector<T> node;

public:
    SegmentTree(vector<T> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,mp(INF,INF));
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,T 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]);
        }
    }

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


int main(){
    int n,q;cin >> n >> q;
    vector<P> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].fs;
        v[i].sc = i;
    }
    SegmentTree<P> seg(v);
    while(q--){
        int t,l,r;cin >> t >> l >> r;
        if(t == 1){
            l--,r--;
            auto p = seg.getmin(l,l+1);
            seg.update(l, mp(seg.getmin(r,r+1).fs,l));
            seg.update(r, mp(p.fs, r));
        }
        else{
            l--;
            cout << seg.getmin(l, r).sc + 1 << endl;
        }
    }
    return 0;
}
0