結果

問題 No.259 セグメントフィッシング+
ユーザー lam6er
提出日時 2025-04-09 20:56:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,064 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 54,080 KB
最終ジャッジ日時 2025-04-09 20:56:52
合計ジャッジ時間 5,224 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 3 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    Q = int(input[ptr])
    ptr += 1
    
    add_queries = []  # list of (direction, t0, y0, z)
    c_queries = []    # list of (t, y, z)
    
    for _ in range(Q):
        type_ = input[ptr]
        ptr += 1
        t = int(input[ptr])
        ptr += 1
        y = int(input[ptr])
        ptr += 1
        z = int(input[ptr])
        ptr += 1
        
        if type_ == 'C':
            c_queries.append( (t, y, z) )
        else:
            add_queries.append( (type_, t, y, z) )
    
    results = []
    add_list = add_queries
    for cq in c_queries:
        t_query, y_target, z_target = cq
        total = 0
        
        for aq in add_list:
            aq_type, t0, y0, z = aq
            if t0 > t_query:
                continue
            
            delta = t_query - t0
            if aq_type == 'L':
                # Left fish
                if delta <= y0:
                    pos = y0 - delta
                else:
                    k = delta - y0 - 1
                    T = 2 * (N - 1)
                    r = k % T
                    if r < N - 1:
                        pos = r
                    else:
                        pos = (N - 1) - (r - (N - 1))
                
                if y_target <= pos < z_target:
                    total += z
            else:
                # Right fish
                max_stage1 = (N - 1) - y0
                if delta <= max_stage1:
                    pos = y0 + delta
                else:
                    k = delta - max_stage1 - 1
                    T = 2 * (N - 1)
                    r = k % T
                    if r < N - 1:
                        pos = (N - 1) - r
                    else:
                        pos = r - (N - 1)
                
                if y_target <= pos < z_target:
                    total += z
        
        results.append(total)
    
    for res in results:
        print(res)

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