結果

問題 No.875 Range Mindex Query
ユーザー kyort0nkyort0n
提出日時 2019-09-06 21:25:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 1,891 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 174,236 KB
実行使用メモリ 5,240 KB
最終ジャッジ日時 2023-09-06 22:16:34
合計ジャッジ時間 4,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,148 KB
testcase_01 AC 4 ms
5,136 KB
testcase_02 AC 5 ms
5,132 KB
testcase_03 AC 3 ms
5,216 KB
testcase_04 AC 4 ms
5,072 KB
testcase_05 AC 4 ms
5,152 KB
testcase_06 AC 4 ms
5,156 KB
testcase_07 AC 5 ms
5,076 KB
testcase_08 AC 4 ms
5,148 KB
testcase_09 AC 4 ms
5,156 KB
testcase_10 AC 5 ms
5,160 KB
testcase_11 AC 167 ms
5,240 KB
testcase_12 AC 139 ms
5,224 KB
testcase_13 AC 114 ms
5,092 KB
testcase_14 AC 112 ms
5,104 KB
testcase_15 AC 156 ms
5,096 KB
testcase_16 AC 202 ms
5,076 KB
testcase_17 AC 221 ms
5,104 KB
testcase_18 AC 217 ms
5,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = 1e9;

struct SegmentTree {
private:
    int n;
    vector<i_i> node;
 
public:
    SegmentTree() {
        int sz = 100050;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, {INF,0});
        for(int i=0; i<sz; i++) node[i+n-1] = {INF,i};
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void update(int x, int val) {
        x += (n - 1);
        node[x].first = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }
    // hannkaikukann 
    i_i 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 {INF,0};
        if(a <= l && r <= b) return node[k];
 
        i_i vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        i_i vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};



int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    SegmentTree seg;
    for(int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        seg.update(i, a);
    }
    while(Q--) {
        int ope, l, r;
        cin >> ope >> l >> r;
        if(ope == 1) {
            int v1 = seg.getmin(l, l+1).first;
            int v2 = seg.getmin(r, r+1).first;
            seg.update(l, v2);
            seg.update(r,v1);
            continue;
        } else {
            cout << seg.getmin(l, r + 1).second << endl;
        }
    }
    return 0;
}
0