結果

問題 No.875 Range Mindex Query
ユーザー Y17Y17
提出日時 2019-09-06 21:27:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 1,647 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 150,980 KB
実行使用メモリ 5,216 KB
最終ジャッジ日時 2023-09-06 22:26:56
合計ジャッジ時間 4,040 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 197 ms
5,096 KB
testcase_12 AC 160 ms
4,376 KB
testcase_13 AC 135 ms
5,120 KB
testcase_14 AC 136 ms
5,216 KB
testcase_15 AC 191 ms
5,104 KB
testcase_16 AC 244 ms
5,132 KB
testcase_17 AC 270 ms
5,104 KB
testcase_18 AC 261 ms
5,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    //void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(r, seg[--b]);
        }
        return merge(l, r);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    typedef pair<int, int> P;

    SegmentTree<P> seg(n, {INT_MAX, -1}, [](P a, P b){
            return min(a, b);
            });

    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        seg[i] = {a, i+1};
    }

    seg.build();

    for(int p = 0;p < q;p++){
        int a, b, c;
        cin >> a >> b >> c;
        b--;
        c--;
        if(a == 1){
            int l = seg[b].first;
            int r = seg[c].first;
            seg.update(b, {r, b+1});
            seg.update(c, {l, c+1});
        }else{
            cout << seg.get(b, c+1).second  << endl;
        }
    }

    return 0;
}
0