結果

問題 No.875 Range Mindex Query
ユーザー pes_magicpes_magic
提出日時 2020-01-28 00:31:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,647 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 73,992 KB
実行使用メモリ 5,440 KB
最終ジャッジ日時 2023-10-12 18:11:48
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In instantiation of ‘T SegTree<T>::update_(T&, T) [with T = std::pair<int, int>]’:
main.cpp:12:9:   required from ‘void SegTree<T>::update(int, T) [with T = std::pair<int, int>]’
main.cpp:47:19:   required from here
main.cpp:35:45: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   35 |     T update_(T& data, T val) { data = val; }
      |                                             ^

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate(a, b);
    }
    T update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return min(a, b); }
    const int N;
    const T def;
    vector<T> mVal; 
};

int main(){
    int N, Q; cin >> N >> Q;
    SegTree<pair<int,int>> seg(N+1, make_pair(N+1, N+1));
    for(int i=1;i<=N;i++){
        int a; cin >> a;
        seg.update(i, make_pair(a, i));
    }
    for(int i=0;i<Q;i++){
        int q, l, r; cin >> q >> l >> r;
        if(q == 1){
            int a = seg.get(l, l+1).first;
            int b = seg.get(r, r+1).first;
            seg.update(l, make_pair(b, l));
            seg.update(r, make_pair(a, r));
        } else {
            cout << seg.get(l, r+1).second << endl;
        }
    }
}
0