結果
| 問題 |
No.2154 あさかつの参加人数
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2022-12-10 01:02:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 255 ms / 2,000 ms |
| コード長 | 1,994 bytes |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 101,632 KB |
| 最終ジャッジ日時 | 2024-10-14 23:22:58 |
| 合計ジャッジ時間 | 9,369 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
class Imos_1:
def __init__(self, N):
""" 区間 0<=t<N に対する Imos 法を準備する.
"""
self.__N=N
self.list=[0]*(N+1)
def __len__(self):
return len(self.list)-1
def add(self, l, r, x=1):
"""閉区間 [l, r] に x を加算する."""
assert 0<=l<self.__N
assert 0<=r<self.__N
if l<=r:
self.list[l]+=x
self.list[r+1]-=x
def cumulative_sum(self):
"""累積和を求める.
"""
X=self.list.copy()[:-1]
for i in range(1,len(self)):
X[i]+=X[i-1]
return X
#=================================================
from collections import defaultdict
class Sparse_Imos_1:
def __init__(self):
self.dict=defaultdict(int)
def add(self, l, r, x=1):
"""閉区間 [l,r] に x を加算する.
"""
if l<=r:
self.dict[l]+=x
self.dict[r+1]-=x
def cumulative_sum(self, since, until):
"""累積和を求める.
[Output]
(y, l, r) という形のリスト. ただし, (y, l, r) は l<=x<=y の範囲では y であるということを意味する.
"""
Y=[]
S=0
t_old=since
dic=self.dict
for t in sorted(dic):
if t>until:
break
if dic[t]==0:
continue
if t_old<=t-1:
Y.append((S, t_old,t-1))
S+=dic[t]
t_old=t
if t_old<=until:
Y.append((S, t_old,until))
return Y
#==================================================
def solve():
N,M=map(int,input().split())
I=Imos_1(N+1)
for _ in range(M):
L,R=map(int,input().split())
I.add(R,L)
J=I.cumulative_sum()
return J[1:N+1][::-1]
#==================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write
write("\n".join(map(str,solve())))
Kazun