結果
問題 | No.2549 Paint Eggs |
ユーザー |
|
提出日時 | 2023-11-14 12:54:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 2,033 bytes |
コンパイル時間 | 2,192 ms |
コンパイル使用メモリ | 198,512 KB |
最終ジャッジ日時 | 2025-02-17 21:59:11 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
ソースコード
#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; // parentdat[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;}