結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー maspymaspy
提出日時 2020-04-01 02:38:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 878 ms / 5,000 ms
コード長 2,517 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 51,316 KB
最終ジャッジ日時 2024-09-22 10:37:48
合計ジャッジ時間 26,520 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 36 ms
11,136 KB
testcase_04 AC 35 ms
11,008 KB
testcase_05 AC 36 ms
11,136 KB
testcase_06 AC 36 ms
11,008 KB
testcase_07 AC 35 ms
11,136 KB
testcase_08 AC 34 ms
11,008 KB
testcase_09 AC 34 ms
10,880 KB
testcase_10 AC 33 ms
11,008 KB
testcase_11 AC 34 ms
11,008 KB
testcase_12 AC 708 ms
25,472 KB
testcase_13 AC 781 ms
31,240 KB
testcase_14 AC 649 ms
29,152 KB
testcase_15 AC 854 ms
32,220 KB
testcase_16 AC 709 ms
30,208 KB
testcase_17 AC 728 ms
30,084 KB
testcase_18 AC 691 ms
25,452 KB
testcase_19 AC 651 ms
29,052 KB
testcase_20 AC 639 ms
29,144 KB
testcase_21 AC 793 ms
31,012 KB
testcase_22 AC 788 ms
31,248 KB
testcase_23 AC 698 ms
25,472 KB
testcase_24 AC 718 ms
29,988 KB
testcase_25 AC 603 ms
22,528 KB
testcase_26 AC 498 ms
21,132 KB
testcase_27 AC 790 ms
31,204 KB
testcase_28 AC 799 ms
31,264 KB
testcase_29 AC 637 ms
29,064 KB
testcase_30 AC 869 ms
32,184 KB
testcase_31 AC 816 ms
31,340 KB
testcase_32 AC 642 ms
30,024 KB
testcase_33 AC 718 ms
30,996 KB
testcase_34 AC 604 ms
22,724 KB
testcase_35 AC 878 ms
35,628 KB
testcase_36 AC 613 ms
22,580 KB
testcase_37 AC 729 ms
51,316 KB
testcase_38 AC 559 ms
36,240 KB
testcase_39 AC 523 ms
36,380 KB
testcase_40 AC 551 ms
36,276 KB
testcase_41 AC 767 ms
42,428 KB
testcase_42 AC 759 ms
42,420 KB
testcase_43 AC 596 ms
25,940 KB
testcase_44 AC 784 ms
33,516 KB
testcase_45 AC 734 ms
51,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict

N = int(readline())
L = tuple(map(int, readline().split()))
T = int(readline())
query = readlines()

AC_count = [0] * N
player_score = defaultdict(int)
scores = []

for t, q in enumerate(query):
    name, prob = q.split()
    if prob == b'?':
        continue
    p = ord(prob) - ord('A')
    lv = L[p]
    AC_count[p] += 1
    rank = AC_count[p]
    player_score[name] += 50 * lv + (250 * lv) // (4 + rank)
    x = t - (T + 10) * player_score[name]
    scores.append(x)

compress = {x: i for i, x in enumerate(sorted(scores), 1)}


class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)

    def build(self, seq):
        data = seq
        size = self.size
        for i, x in enumerate(data):
            j = i + (i & (-i))
            if j < size:
                data[j] += data[i]
        self.data = data

    def __repr__(self):
        return self.data.__repr__()

    def get_sum(self, i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i

    def find_kth_element(self, k):
        data = self.data
        size = self.size
        x, sx = 0, 0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x, sx = y, sy
        return x + 1


AC_count = [0] * N
player_score = defaultdict(int)
player_score_c = defaultdict(int)
n_record = 0

bit = BinaryIndexedTree([0] * (T + 10))

for t, q in enumerate(query):
    name, prob = q.split()
    if prob == b'?':
        x = player_score_c[name]
        print(bit.get_sum(x))
        continue
    p = ord(prob) - ord('A')
    lv = L[p]
    AC_count[p] += 1
    rank = AC_count[p]
    player_score[name] += 50 * lv + (250 * lv) // (4 + rank)

    before = player_score_c[name]
    after = compress[t - (T + 10) * player_score[name]]
    player_score_c[name] = after
    if not before:
        n_record += 1
    if before:
        bit.add(before, -1)
    bit.add(after, 1)
0