Submission #5391637
Source Code Expand
# -*- coding: utf-8 -*-
#import matplotlib.pyplot as plt
#import numpy as np
from bisect import bisect
from operator import itemgetter
def inpl(): return 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):
if i == 0:
return
while 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) * 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 |
1582 Byte |
Status |
TLE |
Exec Time |
2111 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 |
161 ms |
38256 KB |
00_example_02.txt |
AC |
162 ms |
38256 KB |
01.txt |
AC |
164 ms |
38256 KB |
02.txt |
AC |
293 ms |
47852 KB |
03.txt |
AC |
184 ms |
39024 KB |
04.txt |
AC |
166 ms |
38256 KB |
05.txt |
AC |
182 ms |
39280 KB |
06.txt |
AC |
218 ms |
42476 KB |
07.txt |
AC |
164 ms |
38256 KB |
08.txt |
AC |
223 ms |
42092 KB |
09.txt |
AC |
221 ms |
39792 KB |
10.txt |
AC |
165 ms |
38256 KB |
11.txt |
TLE |
2110 ms |
121812 KB |
12.txt |
TLE |
2109 ms |
122128 KB |
13.txt |
AC |
1988 ms |
121940 KB |
14.txt |
AC |
1909 ms |
121708 KB |
15.txt |
AC |
1974 ms |
121580 KB |
16.txt |
TLE |
2110 ms |
121560 KB |
17.txt |
TLE |
2110 ms |
122320 KB |
18.txt |
AC |
1868 ms |
121352 KB |
19.txt |
TLE |
2110 ms |
122064 KB |
20.txt |
TLE |
2110 ms |
122248 KB |
21.txt |
TLE |
2110 ms |
122064 KB |
22.txt |
TLE |
2110 ms |
122064 KB |
23.txt |
TLE |
2111 ms |
123088 KB |
24.txt |
TLE |
2110 ms |
122324 KB |
25.txt |
AC |
1894 ms |
121176 KB |
26.txt |
AC |
1848 ms |
121560 KB |
27.txt |
TLE |
2110 ms |
123088 KB |
28.txt |
AC |
1977 ms |
121560 KB |
29.txt |
TLE |
2110 ms |
122192 KB |
30.txt |
AC |
1941 ms |
121432 KB |
31.txt |
AC |
1925 ms |
123088 KB |
32.txt |
AC |
1762 ms |
118676 KB |
33.txt |
AC |
1802 ms |
118096 KB |
34.txt |
TLE |
2109 ms |
122124 KB |
35.txt |
TLE |
2110 ms |
122064 KB |
36.txt |
AC |
165 ms |
38256 KB |
37.txt |
AC |
768 ms |
59608 KB |