結果

問題 No.2549 Paint Eggs
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-25 13:45:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 117,856 KB
最終ジャッジ日時 2023-11-25 13:46:06
合計ジャッジ時間 19,337 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
72,648 KB
testcase_01 AC 77 ms
75,808 KB
testcase_02 AC 68 ms
70,580 KB
testcase_03 AC 91 ms
76,428 KB
testcase_04 AC 80 ms
76,216 KB
testcase_05 AC 84 ms
75,916 KB
testcase_06 AC 89 ms
76,444 KB
testcase_07 AC 80 ms
76,096 KB
testcase_08 AC 64 ms
70,148 KB
testcase_09 AC 91 ms
76,428 KB
testcase_10 AC 403 ms
109,516 KB
testcase_11 AC 382 ms
117,856 KB
testcase_12 AC 386 ms
104,936 KB
testcase_13 AC 413 ms
105,460 KB
testcase_14 AC 276 ms
101,744 KB
testcase_15 AC 138 ms
77,420 KB
testcase_16 AC 355 ms
105,184 KB
testcase_17 AC 360 ms
103,916 KB
testcase_18 AC 261 ms
102,756 KB
testcase_19 AC 346 ms
102,588 KB
testcase_20 AC 524 ms
116,952 KB
testcase_21 AC 498 ms
116,720 KB
testcase_22 AC 545 ms
116,948 KB
testcase_23 AC 519 ms
116,720 KB
testcase_24 AC 557 ms
116,948 KB
testcase_25 AC 413 ms
116,968 KB
testcase_26 AC 399 ms
116,756 KB
testcase_27 AC 433 ms
116,952 KB
testcase_28 AC 550 ms
116,752 KB
testcase_29 AC 474 ms
116,720 KB
testcase_30 AC 549 ms
116,952 KB
testcase_31 AC 450 ms
116,944 KB
testcase_32 AC 512 ms
116,976 KB
testcase_33 AC 478 ms
116,952 KB
testcase_34 AC 429 ms
116,752 KB
testcase_35 AC 566 ms
116,972 KB
testcase_36 AC 521 ms
116,952 KB
testcase_37 AC 514 ms
116,952 KB
testcase_38 AC 447 ms
116,720 KB
testcase_39 AC 477 ms
116,948 KB
testcase_40 AC 520 ms
116,948 KB
testcase_41 AC 504 ms
116,720 KB
testcase_42 AC 529 ms
116,720 KB
testcase_43 AC 494 ms
116,720 KB
testcase_44 AC 512 ms
116,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def segfunc(x, y):
    return min(x, y)


class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def add(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, M, K = map(int, input().split())
C = list(map(int, input().split()))
A = list(map(int, input().split()))
Seg = SegTree([1 << 60] * (M + 1), segfunc, 1 << 60)
for i in range(M):
    Seg.update(i + 1, A[i] * K)
from collections import deque

ans = 1 << 60
q = deque()
for i in range(N):
    c = C[i]
    q.append(c)
    Seg.add(c, -A[c - 1])
    if len(q) == K:
        ans = min(ans, Seg.query(1, M + 1))
        v = q.popleft()
        Seg.add(v, A[v - 1])
print(ans)
0