結果

問題 No.2549 Paint Eggs
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-25 13:44:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,706 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 18,580 KB
最終ジャッジ日時 2023-11-25 13:45:03
合計ジャッジ時間 6,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
17,044 KB
testcase_01 AC 48 ms
10,240 KB
testcase_02 AC 42 ms
10,368 KB
testcase_03 AC 45 ms
10,240 KB
testcase_04 AC 43 ms
10,240 KB
testcase_05 AC 46 ms
10,240 KB
testcase_06 AC 52 ms
10,240 KB
testcase_07 AC 45 ms
10,240 KB
testcase_08 AC 35 ms
10,112 KB
testcase_09 AC 52 ms
10,240 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

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