Submission #5391295


Source Code Expand

from bisect import bisect
from operator import itemgetter
inpl = lambda: list(map(int, input().split()))


class BIT:
    from math import log2

    def __init__(self, N):
        self.size = 2 ** (-int(-log2(N)//1))
        self.tree = [0]*(self.size + 1)

    def sum(self, i):
        res = 0
        while i:
            res += self.tree[i]
            i -= (i & -(i))
        return res

    def add(self, i, x):
        while 1 <= i <= self.size:
            self.tree[i] += x
            i += (i & -(i))


class RABIT():
    # range add BIT
    def __init__(self, N):
        self.bit0 = BIT(N)
        self.bit1 = BIT(N)

    def sum(self, i):
        return i*self.bit1.sum(i) + self.bit0.sum(i)

    def add_range(self, l, r, x):
        self.bit0.add(l, -x*(l-1))
        self.bit1.add(l, x)
        self.bit0.add(r+1, x*r)
        self.bit1.add(r+1, -x)

    def get_range(self, l, r):
        return self.sum(r) - self.sum(l-1)


N, M = inpl()
R, L, S = [], [], []
Q = []
for _ in range(N):
    l, r = inpl()
    Q.append((l, r, (r-l+1)))

Q = sorted(Q, key=itemgetter(2), reverse=True)
rabit = RABIT(M+1)

for i in range(1, M+1):
    while Q and Q[-1][2] < i:
        l, r, _ = Q.pop()
        rabit.add_range(l, r, 1)
    ans = len(Q)
    for j in range(i, M+1, i):
        ans += rabit.get_range(j, j)
    print(ans)

Submission Info

Submission Time
Task E - Snuke Line
User nadare881
Language PyPy3 (2.4.0)
Score 0
Code Size 1395 Byte
Status RE
Exec Time 170 ms
Memory 38384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
RE × 2
RE × 39
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt
Case Name Status Exec Time Memory
00_example_01.txt RE 167 ms 38384 KB
00_example_02.txt RE 162 ms 38256 KB
01.txt RE 163 ms 38256 KB
02.txt RE 162 ms 38256 KB
03.txt RE 168 ms 38256 KB
04.txt RE 163 ms 38256 KB
05.txt RE 164 ms 38384 KB
06.txt RE 163 ms 38256 KB
07.txt RE 163 ms 38256 KB
08.txt RE 163 ms 38256 KB
09.txt RE 162 ms 38256 KB
10.txt RE 163 ms 38256 KB
11.txt RE 165 ms 38256 KB
12.txt RE 162 ms 38256 KB
13.txt RE 162 ms 38256 KB
14.txt RE 163 ms 38256 KB
15.txt RE 162 ms 38256 KB
16.txt RE 168 ms 38256 KB
17.txt RE 164 ms 38256 KB
18.txt RE 161 ms 38256 KB
19.txt RE 168 ms 38256 KB
20.txt RE 164 ms 38256 KB
21.txt RE 162 ms 38384 KB
22.txt RE 162 ms 38256 KB
23.txt RE 163 ms 38256 KB
24.txt RE 164 ms 38256 KB
25.txt RE 162 ms 38256 KB
26.txt RE 163 ms 38256 KB
27.txt RE 165 ms 38256 KB
28.txt RE 164 ms 38256 KB
29.txt RE 170 ms 38256 KB
30.txt RE 166 ms 38256 KB
31.txt RE 167 ms 38256 KB
32.txt RE 166 ms 38256 KB
33.txt RE 164 ms 38256 KB
34.txt RE 165 ms 38256 KB
35.txt RE 164 ms 38256 KB
36.txt RE 164 ms 38384 KB
37.txt RE 164 ms 38256 KB