結果

問題 No.2662 Installing Cell Towers
ユーザー titia
提出日時 2024-03-07 00:18:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 53,504 KB
最終ジャッジ日時 2024-09-29 18:37:56
合計ジャッジ時間 7,773 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
ANS=[0]*N
LIST=[[] for i in range(N)]
LIST2=[[] for i in range(N)]

for i in range(M):
    p,q=map(int,input().split())
    p-=1
    LIST[p].append((q,1))

    if p+q<N:
        LIST[p+q].append((0,-1))

    LIST2[p].append((q,1))
    if p-q>=0:
        LIST2[p-q].append((0,-1))
    ANS[p]+=q

NOW,count=0,0

for i in range(N):
    NOW-=count
    ANS[i]+=NOW
    
    for p,c in LIST[i]:
        NOW+=p
        count+=c
        
NOW,count=0,0
for i in range(N-1,-1,-1):

    NOW-=count
    ANS[i]+=NOW

    for p,c in LIST2[i]:
        NOW+=p
        count+=c

print(*ANS)
0