結果

問題 No.151 セグメントフィッシング
ユーザー gew1fw
提出日時 2025-06-12 13:38:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,797 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 86,172 KB
最終ジャッジ日時 2025-06-12 13:43:45
合計ジャッジ時間 22,074 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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

    groups = []
    current_time = 0

    for _ in range(Q):
        current_time += 1
        x = input[ptr]
        ptr += 1
        y = int(input[ptr])
        ptr += 1
        z = int(input[ptr])
        ptr += 1

        if x == 'L' or x == 'R':
            groups.append((current_time, x, y, z))
        else:
            # Query type 'C'
            # y is the start, z is the end of interval [y, z)
            count = 0
            t = current_time
            for group in groups:
                t0, dir, x_pos, z_count = group
                s = t - t0
                if s < 0:
                    continue
                if dir == 'L':
                    if s <= x_pos:
                        pos = x_pos - s
                    else:
                        s_prime = s - (x_pos + 1)
                        cycle = 2 * (N - 1)
                        s_mod = s_prime % cycle
                        if s_mod < (N - 1):
                            pos = s_mod
                        else:
                            pos = 2 * (N - 1) - s_mod
                else:
                    if s <= (N - 1 - x_pos):
                        pos = x_pos + s
                    else:
                        s_prime = s - (N - x_pos)
                        cycle = 2 * (N - 1)
                        s_mod = s_prime % cycle
                        if s_mod < (N - 1):
                            pos = (N - 1) - s_mod
                        else:
                            pos = s_mod - (N - 1) - 1
                if y <= pos < z:
                    count += z_count
            print(count)

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