# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22143 | xhae? xhae! (#42) | 구간들 (KRIII5P_3) | Cpython 3 | 1071 ms | 32 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# date: 2017-04-29
# contest: 5th kriiicon
# problem: I
# author: xhae
import itertools
import heapq
MOD = 1000000007
pows = [1] * 1000001
for i in range(1, 100001):
pows[i] = pows[i - 1] * 2 % MOD
n = int(input())
_data = sorted([tuple(map(int, input().split())) for i in range(n)])
data = []
for cpair in _data:
if cpair[0] >= cpair[1]:
continue
data += [cpair]
coords = []
for coord in data:
coords += [coord[0]]
coords += [coord[1]]
coords = [k for k, g in itertools.groupby(sorted(coords))]
# sub problem 1
endQueue = []
di = 0
totLen = 0
for i in range(len(coords) - 1):
while di < len(data):
if data[di][0] <= coords[i]:
heapq.heappush(endQueue, data[di][1])
di += 1
else:
break
while len(endQueue) > 0 and endQueue[0] <= coords[i]:
heapq.heappop(endQueue)
curLen = coords[i + 1] - coords[i]
totLen = (totLen + curLen * (pows[len(endQueue)] - 1)) % MOD
# sub problem 2
nCases = 0
endQueue = []
for coord in data:
while len(endQueue) > 0 and endQueue[0] <= coord[0]:
heapq.heappop(endQueue)
nCases = (nCases + pows[len(endQueue)]) % MOD
heapq.heappush(endQueue, coord[1])
print(totLen, nCases)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |