Submission #5391522
Source Code Expand
from bisect import bisect
from operator import itemgetter
inpl = lambda: list(map(int, input().split()))
class BIT:
def __init__(self, N):
self.size = 2 ** (int.bit_length(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)
Lmin = M
Rmax = 0
for i in range(1, M+1):
while Q and Q[-1][2] < i:
l, r, _ = Q.pop()
rabit.add_range(l, r, 1)
Lmin = min(Lmin, l)
Rmax = max(Rmax, r)
ans = len(Q)
for j in range((Lmin//i + 1) * i, Rmax+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 |
1463 Byte |
Status |
WA |
Exec Time |
2110 ms |
Memory |
123088 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 700 |
Status |
|
|
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 |
AC |
167 ms |
38384 KB |
00_example_02.txt |
AC |
166 ms |
38256 KB |
01.txt |
AC |
166 ms |
38256 KB |
02.txt |
AC |
281 ms |
46828 KB |
03.txt |
AC |
188 ms |
39024 KB |
04.txt |
AC |
169 ms |
38256 KB |
05.txt |
WA |
184 ms |
39280 KB |
06.txt |
WA |
219 ms |
42476 KB |
07.txt |
AC |
165 ms |
38256 KB |
08.txt |
WA |
227 ms |
42092 KB |
09.txt |
AC |
217 ms |
39792 KB |
10.txt |
WA |
167 ms |
38256 KB |
11.txt |
TLE |
2110 ms |
121812 KB |
12.txt |
TLE |
2110 ms |
122192 KB |
13.txt |
AC |
1971 ms |
121812 KB |
14.txt |
AC |
1919 ms |
121708 KB |
15.txt |
AC |
1932 ms |
121580 KB |
16.txt |
TLE |
2110 ms |
121560 KB |
17.txt |
TLE |
2110 ms |
122320 KB |
18.txt |
AC |
1960 ms |
121352 KB |
19.txt |
TLE |
2110 ms |
122064 KB |
20.txt |
TLE |
2109 ms |
122328 KB |
21.txt |
TLE |
2110 ms |
122192 KB |
22.txt |
TLE |
2110 ms |
122064 KB |
23.txt |
TLE |
2110 ms |
122576 KB |
24.txt |
TLE |
2110 ms |
122096 KB |
25.txt |
WA |
1883 ms |
121176 KB |
26.txt |
WA |
1868 ms |
121688 KB |
27.txt |
TLE |
2110 ms |
122960 KB |
28.txt |
WA |
1959 ms |
121432 KB |
29.txt |
TLE |
2110 ms |
122192 KB |
30.txt |
TLE |
2049 ms |
121432 KB |
31.txt |
AC |
1978 ms |
123088 KB |
32.txt |
AC |
1912 ms |
118480 KB |
33.txt |
AC |
1846 ms |
118096 KB |
34.txt |
TLE |
2110 ms |
122064 KB |
35.txt |
TLE |
2110 ms |
122192 KB |
36.txt |
AC |
172 ms |
38256 KB |
37.txt |
AC |
797 ms |
59608 KB |