from sys import stdin, stdout
input=stdin.readline
from bisect import bisect_left as lower_bound
from bisect import bisect_right as upper_bound
class FenwickTree:
def __init__(self, x):
bit = self.bit = list(x)
size = self.size = len(bit)
for i in range(size):
j = i | (i + 1)
if j < size:
bit[j] += bit[i]
def update(self, idx, x):
"""updates bit[idx] += x"""
while idx < self.size:
self.bit[idx] += x
idx |= idx + 1
def __call__(self, end):
"""calc sum(bit[:end])"""
x = 0
while end:
x += self.bit[end - 1]
end &= end - 1
return x
def find_kth(self, k):
"""Find largest idx such that sum(bit[:idx]) <= k"""
idx = -1
for d in reversed(range(self.size.bit_length())):
right_idx = idx + (1 << d)
if right_idx < self.size and self.bit[right_idx] <= k:
idx = right_idx
k -= self.bit[idx]
return idx + 1, k
class SortedList:
block_size = 2000
def __init__(self, iterable=()):
self.macro = []
self.micros = [[]]
self.micro_size = [0]
self.fenwick = FenwickTree([0])
self.size = 0
for item in iterable:
self.insert(item)
def insert(self, x):
i = lower_bound(self.macro, x)
j = upper_bound(self.micros[i], x)
self.micros[i].insert(j, x)
self.size += 1
self.micro_size[i] += 1
self.fenwick.update(i, 1)
if len(self.micros[i]) >= self.block_size:
self.micros[i:i + 1] = self.micros[i][:self.block_size >> 1], self.micros[i][self.block_size >> 1:]
self.micro_size[i:i + 1] = self.block_size >> 1, self.block_size >> 1
self.fenwick = FenwickTree(self.micro_size)
self.macro.insert(i, self.micros[i + 1][0])
def pop(self, k=-1):
i, j = self._find_kth(k)
self.size -= 1
self.micro_size[i] -= 1
self.fenwick.update(i, -1)
return self.micros[i].pop(j)
def __getitem__(self, k):
i, j = self._find_kth(k)
return self.micros[i][j]
def count(self, x):
return self.upper_bound(x) - self.lower_bound(x)
def __contains__(self, x):
return self.count(x) > 0
def lower_bound(self, x):
i = lower_bound(self.macro, x)
return self.fenwick(i) + lower_bound(self.micros[i], x)
def upper_bound(self, x):
i = upper_bound(self.macro, x)
return self.fenwick(i) + upper_bound(self.micros[i], x)
def _find_kth(self, k):
return self.fenwick.find_kth(k + self.size if k < 0 else k)
def __len__(self):
return self.size
def __iter__(self):
return (x for micro in self.micros for x in micro)
def __repr__(self):
return str(list(self))
def main():
# n^4/3*log(n)
N = int(input())
L = SortedList()
A,B = list(map(int, input().split()))
L.insert((A,-B))
stdout.write('1\n')
for _ in range(N-1):
A,B = list(map(int, input().split()))
i = upper_bound(L,(A,-B))
if i==len(L):
if B<=-L[-1][1]:
L.insert((A,-B))
else:
L.insert((A,-B))
while len(L)>1 and B>-L[-2][1] and A>L[-2][0]:
#print(L,A,-B)
L.pop(-2)
#print(L)
else:
if B<-L[i][1] and A<L[i][0]:
pass
else:
L.insert((A,-B))
while i>0 and B>-L[i-1][1] and A>L[i-1][0]:
#print(L,A,-B)
L.pop(i-1)
i-=1
#print(L)
stdout.write(str(len(L))+'\n')
main()
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 45ms | 80684 KiB | ||||
2 | Elfogadva | 270ms | 106756 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Elfogadva | 45ms | 81104 KiB | ||||
4 | Elfogadva | 46ms | 80840 KiB | ||||
5 | Elfogadva | 75ms | 88604 KiB | ||||
6 | Elfogadva | 107ms | 93508 KiB | ||||
subtask3 | 10/10 | ||||||
7 | Elfogadva | 43ms | 81368 KiB | ||||
8 | Elfogadva | 56ms | 87880 KiB | ||||
9 | Elfogadva | 61ms | 89096 KiB | ||||
10 | Elfogadva | 65ms | 86548 KiB | ||||
11 | Elfogadva | 87ms | 90904 KiB | ||||
12 | Elfogadva | 82ms | 89988 KiB | ||||
13 | Elfogadva | 108ms | 93940 KiB | ||||
14 | Elfogadva | 115ms | 95652 KiB | ||||
subtask4 | 0/10 | ||||||
15 | Elfogadva | 45ms | 82680 KiB | ||||
16 | Elfogadva | 48ms | 82080 KiB | ||||
17 | Elfogadva | 83ms | 90940 KiB | ||||
18 | Elfogadva | 104ms | 94804 KiB | ||||
19 | Elfogadva | 112ms | 94776 KiB | ||||
20 | Elfogadva | 131ms | 96304 KiB | ||||
21 | Elfogadva | 141ms | 96956 KiB | ||||
22 | Időlimit túllépés | 460ms | 40992 KiB | ||||
subtask5 | 25/25 | ||||||
23 | Elfogadva | 71ms | 89360 KiB | ||||
24 | Elfogadva | 83ms | 90076 KiB | ||||
25 | Elfogadva | 108ms | 95432 KiB | ||||
26 | Elfogadva | 128ms | 94780 KiB | ||||
27 | Elfogadva | 192ms | 103392 KiB | ||||
28 | Elfogadva | 226ms | 104960 KiB | ||||
29 | Elfogadva | 256ms | 106780 KiB | ||||
30 | Elfogadva | 259ms | 107340 KiB | ||||
subtask6 | 0/50 | ||||||
31 | Elfogadva | 45ms | 82672 KiB | ||||
32 | Elfogadva | 277ms | 108988 KiB | ||||
33 | Elfogadva | 45ms | 81104 KiB | ||||
34 | Elfogadva | 46ms | 80840 KiB | ||||
35 | Elfogadva | 75ms | 88604 KiB | ||||
36 | Elfogadva | 107ms | 93508 KiB | ||||
37 | Elfogadva | 43ms | 81368 KiB | ||||
38 | Elfogadva | 56ms | 87880 KiB | ||||
39 | Elfogadva | 61ms | 89096 KiB | ||||
40 | Elfogadva | 65ms | 86548 KiB | ||||
41 | Elfogadva | 87ms | 90904 KiB | ||||
42 | Elfogadva | 82ms | 89988 KiB | ||||
43 | Elfogadva | 108ms | 93940 KiB | ||||
44 | Elfogadva | 115ms | 95652 KiB | ||||
45 | Elfogadva | 45ms | 82680 KiB | ||||
46 | Elfogadva | 48ms | 82080 KiB | ||||
47 | Elfogadva | 83ms | 90940 KiB | ||||
48 | Elfogadva | 104ms | 94804 KiB | ||||
49 | Elfogadva | 112ms | 94776 KiB | ||||
50 | Elfogadva | 131ms | 96304 KiB | ||||
51 | Elfogadva | 141ms | 96956 KiB | ||||
52 | Időlimit túllépés | 460ms | 40992 KiB | ||||
53 | Elfogadva | 71ms | 89360 KiB | ||||
54 | Elfogadva | 83ms | 90076 KiB | ||||
55 | Elfogadva | 108ms | 95432 KiB | ||||
56 | Elfogadva | 128ms | 94780 KiB | ||||
57 | Elfogadva | 192ms | 103392 KiB | ||||
58 | Elfogadva | 226ms | 104960 KiB | ||||
59 | Elfogadva | 256ms | 106780 KiB | ||||
60 | Elfogadva | 259ms | 107340 KiB | ||||
61 | Elfogadva | 114ms | 94960 KiB | ||||
62 | Elfogadva | 286ms | 115276 KiB | ||||
63 | Elfogadva | 115ms | 95252 KiB | ||||
64 | Időlimit túllépés | 425ms | 117120 KiB | ||||
65 | Elfogadva | 119ms | 96496 KiB | ||||
66 | Elfogadva | 115ms | 95444 KiB | ||||
67 | Elfogadva | 115ms | 95860 KiB | ||||
68 | Elfogadva | 111ms | 94336 KiB | ||||
69 | Elfogadva | 307ms | 109528 KiB | ||||
70 | Időlimit túllépés | 477ms | 42392 KiB |