結果

問題 No.2154 あさかつの参加人数
ユーザー 👑 KazunKazun
提出日時 2022-12-10 01:02:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,994 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 101,252 KB
最終ジャッジ日時 2024-04-22 23:31:59
合計ジャッジ時間 7,570 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 206 ms
97,576 KB
testcase_01 AC 215 ms
98,092 KB
testcase_02 AC 205 ms
97,732 KB
testcase_03 AC 201 ms
97,800 KB
testcase_04 AC 209 ms
97,776 KB
testcase_05 AC 112 ms
76,256 KB
testcase_06 AC 169 ms
88,052 KB
testcase_07 AC 132 ms
89,076 KB
testcase_08 AC 128 ms
96,704 KB
testcase_09 AC 74 ms
86,792 KB
testcase_10 AC 122 ms
92,124 KB
testcase_11 AC 186 ms
95,396 KB
testcase_12 AC 152 ms
92,856 KB
testcase_13 AC 108 ms
82,320 KB
testcase_14 AC 165 ms
91,880 KB
testcase_15 AC 131 ms
90,280 KB
testcase_16 AC 162 ms
95,328 KB
testcase_17 AC 178 ms
91,780 KB
testcase_18 AC 190 ms
96,908 KB
testcase_19 AC 60 ms
78,308 KB
testcase_20 AC 163 ms
92,028 KB
testcase_21 AC 71 ms
86,280 KB
testcase_22 AC 94 ms
97,460 KB
testcase_23 AC 203 ms
97,412 KB
testcase_24 AC 205 ms
101,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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())))
0