結果

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

ソースコード

diff #

n, q = map(int, input().split())
events = []
period = 2 * (n - 1)
n_minus_1 = n - 1

for current_time in range(1, q + 1):
    parts = input().split()
    if parts[0] in ('L', 'R'):
        direction = parts[0]
        y = int(parts[1])
        z = int(parts[2])
        events.append((direction, y, current_time, z))
    else:
        y_query = int(parts[1])
        z_query = int(parts[2])
        total = 0
        for event in events:
            dir_e, y_e, t0_e, z_e = event
            if t0_e > current_time:
                continue
            delta = current_time - t0_e
            if dir_e == 'R':
                initial_steps = n_minus_1 - y_e
                if delta <= initial_steps:
                    pos = y_e + delta
                else:
                    delta_bounce = delta - initial_steps - 1
                    if delta_bounce < 0:
                        pos = n_minus_1
                    else:
                        remaining = delta_bounce % period
                        if remaining < n_minus_1:
                            pos = n_minus_1 - remaining
                        else:
                            pos = remaining - n_minus_1
            else:  # 'L'
                initial_steps = y_e
                if delta <= initial_steps:
                    pos = y_e - delta
                else:
                    delta_bounce = delta - initial_steps - 1
                    if delta_bounce < 0:
                        pos = 0
                    else:
                        remaining = delta_bounce % period
                        if remaining < n_minus_1:
                            pos = remaining
                        else:
                            pos = 2 * n_minus_1 - remaining
            if y_query <= pos < z_query:
                total += z_e
        print(total)
0