結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー maspymaspy
提出日時 2020-04-01 02:38:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 836 ms / 5,000 ms
コード長 2,517 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,244 KB
実行使用メモリ 50,648 KB
最終ジャッジ日時 2023-10-23 16:13:57
合計ジャッジ時間 24,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,332 KB
testcase_01 AC 33 ms
10,332 KB
testcase_02 AC 32 ms
10,332 KB
testcase_03 AC 35 ms
10,500 KB
testcase_04 AC 33 ms
10,488 KB
testcase_05 AC 35 ms
10,500 KB
testcase_06 AC 33 ms
10,480 KB
testcase_07 AC 34 ms
10,488 KB
testcase_08 AC 33 ms
10,480 KB
testcase_09 AC 34 ms
10,488 KB
testcase_10 AC 32 ms
10,468 KB
testcase_11 AC 34 ms
10,484 KB
testcase_12 AC 631 ms
24,944 KB
testcase_13 AC 703 ms
30,412 KB
testcase_14 AC 581 ms
28,488 KB
testcase_15 AC 836 ms
31,660 KB
testcase_16 AC 639 ms
29,632 KB
testcase_17 AC 638 ms
29,632 KB
testcase_18 AC 618 ms
24,892 KB
testcase_19 AC 568 ms
28,472 KB
testcase_20 AC 555 ms
28,444 KB
testcase_21 AC 682 ms
30,320 KB
testcase_22 AC 691 ms
30,424 KB
testcase_23 AC 622 ms
24,916 KB
testcase_24 AC 626 ms
29,544 KB
testcase_25 AC 541 ms
21,884 KB
testcase_26 AC 434 ms
20,488 KB
testcase_27 AC 693 ms
30,524 KB
testcase_28 AC 691 ms
30,440 KB
testcase_29 AC 557 ms
28,364 KB
testcase_30 AC 747 ms
31,628 KB
testcase_31 AC 686 ms
30,520 KB
testcase_32 AC 562 ms
29,332 KB
testcase_33 AC 638 ms
30,436 KB
testcase_34 AC 528 ms
21,952 KB
testcase_35 AC 757 ms
34,904 KB
testcase_36 AC 531 ms
21,932 KB
testcase_37 AC 654 ms
50,648 KB
testcase_38 AC 484 ms
35,752 KB
testcase_39 AC 463 ms
35,752 KB
testcase_40 AC 471 ms
35,752 KB
testcase_41 AC 677 ms
42,464 KB
testcase_42 AC 691 ms
42,464 KB
testcase_43 AC 520 ms
25,320 KB
testcase_44 AC 687 ms
32,448 KB
testcase_45 AC 652 ms
50,648 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