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 = 1000
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()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 54ms | 80564 KiB | ||||
2 | Accepted | 280ms | 106888 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 52ms | 80924 KiB | ||||
4 | Accepted | 54ms | 81752 KiB | ||||
5 | Accepted | 85ms | 89040 KiB | ||||
6 | Accepted | 115ms | 93728 KiB | ||||
subtask3 | 10/10 | ||||||
7 | Accepted | 52ms | 81692 KiB | ||||
8 | Accepted | 64ms | 88000 KiB | ||||
9 | Accepted | 65ms | 89460 KiB | ||||
10 | Accepted | 57ms | 86452 KiB | ||||
11 | Accepted | 85ms | 90740 KiB | ||||
12 | Accepted | 90ms | 89780 KiB | ||||
13 | Accepted | 111ms | 94000 KiB | ||||
14 | Accepted | 125ms | 96044 KiB | ||||
subtask4 | 0/10 | ||||||
15 | Accepted | 48ms | 82984 KiB | ||||
16 | Accepted | 54ms | 82792 KiB | ||||
17 | Accepted | 107ms | 91660 KiB | ||||
18 | Accepted | 129ms | 95420 KiB | ||||
19 | Accepted | 123ms | 95360 KiB | ||||
20 | Accepted | 143ms | 97272 KiB | ||||
21 | Accepted | 150ms | 97884 KiB | ||||
22 | Time limit exceeded | 421ms | 38480 KiB | ||||
subtask5 | 25/25 | ||||||
23 | Accepted | 81ms | 90192 KiB | ||||
24 | Accepted | 93ms | 91056 KiB | ||||
25 | Accepted | 112ms | 96328 KiB | ||||
26 | Accepted | 140ms | 96156 KiB | ||||
27 | Accepted | 202ms | 104748 KiB | ||||
28 | Accepted | 240ms | 105332 KiB | ||||
29 | Accepted | 268ms | 108048 KiB | ||||
30 | Accepted | 293ms | 108636 KiB | ||||
subtask6 | 0/50 | ||||||
31 | Accepted | 52ms | 84084 KiB | ||||
32 | Accepted | 273ms | 110160 KiB | ||||
33 | Accepted | 52ms | 80924 KiB | ||||
34 | Accepted | 54ms | 81752 KiB | ||||
35 | Accepted | 85ms | 89040 KiB | ||||
36 | Accepted | 115ms | 93728 KiB | ||||
37 | Accepted | 52ms | 81692 KiB | ||||
38 | Accepted | 64ms | 88000 KiB | ||||
39 | Accepted | 65ms | 89460 KiB | ||||
40 | Accepted | 57ms | 86452 KiB | ||||
41 | Accepted | 85ms | 90740 KiB | ||||
42 | Accepted | 90ms | 89780 KiB | ||||
43 | Accepted | 111ms | 94000 KiB | ||||
44 | Accepted | 125ms | 96044 KiB | ||||
45 | Accepted | 48ms | 82984 KiB | ||||
46 | Accepted | 54ms | 82792 KiB | ||||
47 | Accepted | 107ms | 91660 KiB | ||||
48 | Accepted | 129ms | 95420 KiB | ||||
49 | Accepted | 123ms | 95360 KiB | ||||
50 | Accepted | 143ms | 97272 KiB | ||||
51 | Accepted | 150ms | 97884 KiB | ||||
52 | Time limit exceeded | 421ms | 38480 KiB | ||||
53 | Accepted | 81ms | 90192 KiB | ||||
54 | Accepted | 93ms | 91056 KiB | ||||
55 | Accepted | 112ms | 96328 KiB | ||||
56 | Accepted | 140ms | 96156 KiB | ||||
57 | Accepted | 202ms | 104748 KiB | ||||
58 | Accepted | 240ms | 105332 KiB | ||||
59 | Accepted | 268ms | 108048 KiB | ||||
60 | Accepted | 293ms | 108636 KiB | ||||
61 | Accepted | 125ms | 96388 KiB | ||||
62 | Accepted | 300ms | 116684 KiB | ||||
63 | Accepted | 125ms | 96948 KiB | ||||
64 | Time limit exceeded | 437ms | 116480 KiB | ||||
65 | Accepted | 130ms | 98008 KiB | ||||
66 | Accepted | 126ms | 96712 KiB | ||||
67 | Accepted | 119ms | 97152 KiB | ||||
68 | Accepted | 120ms | 96100 KiB | ||||
69 | Accepted | 337ms | 111104 KiB | ||||
70 | Time limit exceeded | 472ms | 42116 KiB |