結果

問題 No.2338 Range AtCoder Query
ユーザー gew1fw
提出日時 2025-06-12 14:46:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,536 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,260 KB
最終ジャッジ日時 2025-06-12 14:48:00
合計ジャッジ時間 9,611 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    M = int(input[ptr])
    ptr += 1
    Q = int(input[ptr])
    ptr += 1

    P = []
    S = []
    for _ in range(N):
        p = int(input[ptr])
        ptr += 1
        s = input[ptr]
        ptr += 1
        P.append(p)
        S.append(s)

    queries = []
    for _ in range(Q):
        L = int(input[ptr]) - 1  # converting to 0-based index
        ptr += 1
        R = int(input[ptr]) - 1
        ptr += 1
        queries.append((L, R))

    for L, R in queries:
        correct = 0
        penalty = 0
        p_info = dict()  # key: P, value: (has_AC, wa_count, first_AC_pos)

        for i in range(L, R + 1):
            p = P[i]
            s = S[i]

            if p not in p_info:
                if s == 'AC':
                    p_info[p] = (True, 0, i)
                    correct += 1
                else:
                    p_info[p] = (False, 1, i)
            else:
                current = p_info[p]
                has_ac, wa_count, first_ac_pos = current

                if not has_ac:
                    if s == 'AC':
                        # Add this problem's WA count before first AC
                        penalty += wa_count
                        correct += 1
                        p_info[p] = (True, wa_count, i)
                    else:
                        p_info[p] = (False, wa_count + 1, first_ac_pos)

        print(correct, penalty)

if __name__ == "__main__":
    main()
0