結果

問題 No.2549 Paint Eggs
ユーザー Nzt3Nzt3
提出日時 2024-01-11 09:29:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 2,220 bytes
コンパイル時間 3,025 ms
コンパイル使用メモリ 250,724 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2024-01-11 09:29:42
合計ジャッジ時間 7,803 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 58 ms
8,624 KB
testcase_11 AC 56 ms
8,488 KB
testcase_12 AC 47 ms
6,548 KB
testcase_13 AC 56 ms
8,592 KB
testcase_14 AC 39 ms
8,160 KB
testcase_15 AC 5 ms
6,548 KB
testcase_16 AC 50 ms
6,548 KB
testcase_17 AC 38 ms
6,548 KB
testcase_18 AC 36 ms
6,548 KB
testcase_19 AC 44 ms
6,548 KB
testcase_20 AC 80 ms
8,888 KB
testcase_21 AC 80 ms
8,888 KB
testcase_22 AC 82 ms
8,888 KB
testcase_23 AC 81 ms
8,888 KB
testcase_24 AC 86 ms
8,888 KB
testcase_25 AC 69 ms
8,888 KB
testcase_26 AC 71 ms
8,888 KB
testcase_27 AC 73 ms
8,888 KB
testcase_28 AC 83 ms
8,888 KB
testcase_29 AC 76 ms
8,888 KB
testcase_30 AC 80 ms
8,888 KB
testcase_31 AC 71 ms
8,888 KB
testcase_32 AC 79 ms
8,888 KB
testcase_33 AC 74 ms
8,888 KB
testcase_34 AC 73 ms
8,888 KB
testcase_35 AC 83 ms
8,888 KB
testcase_36 AC 81 ms
8,888 KB
testcase_37 AC 77 ms
8,888 KB
testcase_38 AC 71 ms
8,888 KB
testcase_39 AC 76 ms
8,888 KB
testcase_40 AC 86 ms
8,888 KB
testcase_41 AC 83 ms
8,888 KB
testcase_42 AC 82 ms
8,888 KB
testcase_43 AC 82 ms
8,888 KB
testcase_44 AC 86 ms
8,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
namespace Lib {
template <class S, auto op, auto e>
struct segtree {
  int size, _n;
  vector<S> seg;
  segtree(int n) {
    _n = n;
    size = 1;
    while (size < n) size <<= 1;
    seg = vector<S>(size * 2, e());
  }
  void set(int p, S val) {
    p += size;
    seg[p] = val;
    while (p /= 2) {
      seg[p] = op(seg[p * 2], seg[p * 2 + 1]);
    }
  }
  S prod(int l, int r) {
    S retL = e(), retR = e();
    for (l += size, r += size; l < r; l /= 2, r /= 2) {
      if (l % 2) retL = op(retL, seg[l++]);
      if (r % 2) retR = op(seg[--r], retR);
    }
    return op(retL, retR);
  }
  S get(int p) { return seg[p + size]; }
  template <class F>
  int max_right(int L, F f) {
    L += size;
    S sm = e();
    do {
      while (L % 2 == 0) L /= 2;
      if (!f(op(sm, seg[L]))) {
        while (L < size) {
          L *= 2;
          if (f(op(sm, seg[L]))) {
            sm = op(sm, seg[L]);
            L++;
          }
        }
        return L - size;
      }
      sm = op(sm, seg[L]);
      L++;
    } while ((L & -L) != L);
    return _n;
  }

  template <class F>
  int min_left(int R, F f) {
    R += size;
    S sm = e();
    do {
      R--;
      while (R > 1 && R % 2 == 1) R /= 2;
      if (!f(op(seg[R], sm))) {
        while (R < size) {
          R = R * 2 + 1;
          if (f(op(seg[R], sm))) {
            sm = op(seg[R], sm);
            R--;
          }
        }
        return R + 1 - size;
      }
      sm = op(seg[R], sm);
    } while ((R & -R) != R);
    return 0;
  }
};
}  // namespace Lib
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  ll K;
  cin>>N>>M>>K;
  vector C(N,0),A(M,0);
  for(int &i:C)cin>>i,--i;
  for(int &i:A)cin>>i;
  auto seg_op=[](ll a,ll b){
    return min(a,b);
  };
  auto seg_e=[](){
    return (ll)1e18;
  };
  Lib::segtree<ll,seg_op,seg_e> seg(M);
  for(int i=0;i<M;i++){
    seg.set(i,A[i]*K);
  }
  for(int i=0;i<K;i++){
    seg.set(C[i],seg.get(C[i])-A[C[i]]);
  }
  ll ans=seg.prod(0,M);
  for(int i=K;i<N;i++){
    seg.set(C[i-K],seg.get(C[i-K])+A[C[i-K]]);
    seg.set(C[i],seg.get(C[i])-A[C[i]]);
    ans=min(ans,seg.prod(0,M));
  }
  cout<<ans<<'\n';
}
0