結果

問題 No.875 Range Mindex Query
ユーザー t33ft33f
提出日時 2019-09-07 11:07:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,608 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 71,288 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2023-09-08 13:07:29
合計ジャッジ時間 3,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 <iostream>
using namespace std;
class SegTree {
    using T = pair<int, int>;
    static const T& op(const T& lhs, const T& rhs) { // binary operator
        return min(lhs, rhs);
    }
    const int N;
    T *data;
    static int calc_size(int sz) {
        int n = 1;
        while (sz > n) n *= 2;
        return 2*n-1;
    }
public:
    explicit SegTree(int sz) : N(calc_size(sz)) {
        data = new T[2*N-1];
    }
    ~SegTree() { delete[] data; }
    T query(int a, int b, int i = -1, int l = -1, int r = -1) const {
        if (i == -1) { i = 0; l = 0; r = 2*N-1; }
        if (a <= l && r <= b) return data[i];
        int m = (l+r)/2;
        if (b <= m) return query(a, b, 2*i+1, l, m);
        if (m <= a) return query(a, b, 2*i+2, m, r);
        T v1 = query(a, b, 2*i+1, l, m),
          v2 = query(a, b, 2*i+2, m, r);
        return op(v1, v2);
    }
    T get(int i) const {
        return data[i + N - 1];
    }
    void update(int i, int v) {
        int x = i + N - 1;
        data[x] = {v, i};
        while (x > 0) {
            x = (x-1)/2;
            data[x] = op(data[2*x+1], data[2*x+2]);
        }
    }
};

int main() {
    int n, q; cin >> n >> q;
    SegTree st(n);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        st.update(i, a);
    }
    while (q--) {
        int x, l, r; cin >> x >> l >> r;
        l--; r--;
        if (x == 1) {
            int al = st.get(l).first, ar = st.get(r).first;
            st.update(l, ar);
            st.update(r, al);
        } else {
            cout << st.query(l, r+1).second + 1 << endl;
        }
    }
}
0