結果

問題 No.875 Range Mindex Query
ユーザー Ricky_ponRicky_pon
提出日時 2019-10-09 15:03:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,782 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 209,192 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 10:53:44
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 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,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 85 ms
6,944 KB
testcase_12 AC 69 ms
6,940 KB
testcase_13 AC 65 ms
6,940 KB
testcase_14 AC 64 ms
6,944 KB
testcase_15 AC 85 ms
6,944 KB
testcase_16 AC 84 ms
6,940 KB
testcase_17 AC 90 ms
6,944 KB
testcase_18 AC 87 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pil;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

template<class T> struct  SegTree{
    typedef  function<T(T, T)> F;
    int n = 1;
    vector<T> node;
    T et;
    F f, g;

    SegTree(int n_, T et_, F f_, F g_):
    et(et_), f(f_), g(g_){
        while(n < n_) n *= 2;
        node.resize(n*2-1, et);
    }

    void update(int i, T x){
        i += n-1;
        node[i] = g(node[i], x);
        while(i){
            i = (i-1) / 2;
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }

    T query(int a, int b){
        T vl = et, vr = et;
        for(a+=n-1, b+=n-1; a<b; a=(a-1)/2, b=(b-1)/2){
            if(!(a&1)) vl = f(vl, node[a++]);
            if(!(b&1)) vr = f(node[--b], vr);
        }
        return f(vl, vr);
    }
};

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    auto f = [](const pii &p, const pii &q){if(p < q){return p;} return q;};
    auto g = [](const pii &p, const pii &q){return q;};
    SegTree<pii> st(n, pii(100010, -1), f, g);
    rep(i, n){
        int a;
        scanf("%d", &a);
        st.update(i, pii(a, i));
    }

    while(q--){
        int c, l, r;
        scanf("%d%d%d", &c, &l, &r);
        --l; --r;
        if(c == 1) {
            int vl = st.node[l+st.n-1].fi;
            int vr = st.node[r+st.n-1].fi;
            st.update(l, pii(vr, l));
            st.update(r, pii(vl, r));
        }
        else printf("%d\n", st.query(l, r+1).se+1);
    }
}
0