結果

問題 No.2549 Paint Eggs
ユーザー dyktr_06dyktr_06
提出日時 2023-11-14 12:54:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 2,033 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 207,544 KB
実行使用メモリ 10,600 KB
最終ジャッジ日時 2023-11-14 12:54:58
合計ジャッジ時間 9,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 71 ms
10,080 KB
testcase_11 AC 72 ms
9,680 KB
testcase_12 AC 58 ms
7,424 KB
testcase_13 AC 71 ms
9,896 KB
testcase_14 AC 47 ms
9,144 KB
testcase_15 AC 6 ms
6,676 KB
testcase_16 AC 61 ms
7,808 KB
testcase_17 AC 46 ms
7,040 KB
testcase_18 AC 34 ms
6,676 KB
testcase_19 AC 53 ms
7,296 KB
testcase_20 AC 107 ms
10,600 KB
testcase_21 AC 100 ms
10,600 KB
testcase_22 AC 108 ms
10,600 KB
testcase_23 AC 102 ms
10,600 KB
testcase_24 AC 106 ms
10,600 KB
testcase_25 AC 83 ms
10,600 KB
testcase_26 AC 86 ms
10,600 KB
testcase_27 AC 90 ms
10,600 KB
testcase_28 AC 109 ms
10,600 KB
testcase_29 AC 95 ms
10,600 KB
testcase_30 AC 105 ms
10,600 KB
testcase_31 AC 99 ms
10,600 KB
testcase_32 AC 102 ms
10,600 KB
testcase_33 AC 94 ms
10,600 KB
testcase_34 AC 91 ms
10,600 KB
testcase_35 AC 111 ms
10,600 KB
testcase_36 AC 107 ms
10,600 KB
testcase_37 AC 100 ms
10,600 KB
testcase_38 AC 92 ms
10,600 KB
testcase_39 AC 94 ms
10,600 KB
testcase_40 AC 106 ms
10,600 KB
testcase_41 AC 107 ms
10,600 KB
testcase_42 AC 110 ms
10,600 KB
testcase_43 AC 107 ms
10,600 KB
testcase_44 AC 106 ms
10,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename X>
struct SegTree{
    using FX = function<X(X, X)>; // X•X -> X となる関数の型
    int n;
    FX fx;
    const X ex;
    vector<X> dat;

    SegTree(int n_, const FX &fx_, const X &ex_) : n(), fx(fx_), ex(ex_){
        int x = 1;
        while(n_ > x){
            x *= 2;
        }
        n = x;
        dat.assign(n * 2, ex);
    }

    X get(int i) const {
        return dat[i + n];
    }
    
    void set(int i, X x){ dat[i + n] = x; }

    void build(){
        for(int k = n - 1; k >= 1; k--) dat[k] = fx(dat[k * 2], dat[k * 2 + 1]);
    }

    void update(int i, X x){
        i += n;
        dat[i] = x;
        while(i > 0){
            i >>= 1;  // parent
            dat[i] = fx(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    X query(int a, int b){
        X vl = ex;
        X vr = ex;
        int l = a + n;
        int r = b + n;
        while(l < r){
            if(l & 1) vl = fx(vl, dat[l++]);
            if(r & 1) vr = fx(dat[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return fx(vl, vr);
    }
    
    X operator [](int i) const {
        return dat[i + n];
    }
};

const long long INF = 1LL << 60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k; cin >> n >> m >> k;
    vector<long long> c(n), a(m);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        c[i]--;
    }
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }

    auto fx = [](long long a, long long b){
        return min(a, b);
    };
    SegTree<long long> seg(m, fx, INF);
    for(int i = 0; i < m; i++){
        seg.update(i, a[i] * k);
    }
    for(int i = 0; i < k; i++){
        seg.update(c[i], seg[c[i]] - a[c[i]]);
    }

    long long ans = seg.query(0, m);
    for(int i = 0; i < n - k; i++){
        seg.update(c[i], seg[c[i]] + a[c[i]]);
        seg.update(c[i + k], seg[c[i + k]] - a[c[i + k]]);
        ans = min(ans, seg.query(0, m));
    }
    cout << ans << endl;
}
0