107432024-04-10 23:52:3142Főnökszámpypy3Időlimit túllépés 40/100477ms117120 KiB
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ÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva45ms80684 KiB
2Elfogadva270ms106756 KiB
subtask25/5
3Elfogadva45ms81104 KiB
4Elfogadva46ms80840 KiB
5Elfogadva75ms88604 KiB
6Elfogadva107ms93508 KiB
subtask310/10
7Elfogadva43ms81368 KiB
8Elfogadva56ms87880 KiB
9Elfogadva61ms89096 KiB
10Elfogadva65ms86548 KiB
11Elfogadva87ms90904 KiB
12Elfogadva82ms89988 KiB
13Elfogadva108ms93940 KiB
14Elfogadva115ms95652 KiB
subtask40/10
15Elfogadva45ms82680 KiB
16Elfogadva48ms82080 KiB
17Elfogadva83ms90940 KiB
18Elfogadva104ms94804 KiB
19Elfogadva112ms94776 KiB
20Elfogadva131ms96304 KiB
21Elfogadva141ms96956 KiB
22Időlimit túllépés460ms40992 KiB
subtask525/25
23Elfogadva71ms89360 KiB
24Elfogadva83ms90076 KiB
25Elfogadva108ms95432 KiB
26Elfogadva128ms94780 KiB
27Elfogadva192ms103392 KiB
28Elfogadva226ms104960 KiB
29Elfogadva256ms106780 KiB
30Elfogadva259ms107340 KiB
subtask60/50
31Elfogadva45ms82672 KiB
32Elfogadva277ms108988 KiB
33Elfogadva45ms81104 KiB
34Elfogadva46ms80840 KiB
35Elfogadva75ms88604 KiB
36Elfogadva107ms93508 KiB
37Elfogadva43ms81368 KiB
38Elfogadva56ms87880 KiB
39Elfogadva61ms89096 KiB
40Elfogadva65ms86548 KiB
41Elfogadva87ms90904 KiB
42Elfogadva82ms89988 KiB
43Elfogadva108ms93940 KiB
44Elfogadva115ms95652 KiB
45Elfogadva45ms82680 KiB
46Elfogadva48ms82080 KiB
47Elfogadva83ms90940 KiB
48Elfogadva104ms94804 KiB
49Elfogadva112ms94776 KiB
50Elfogadva131ms96304 KiB
51Elfogadva141ms96956 KiB
52Időlimit túllépés460ms40992 KiB
53Elfogadva71ms89360 KiB
54Elfogadva83ms90076 KiB
55Elfogadva108ms95432 KiB
56Elfogadva128ms94780 KiB
57Elfogadva192ms103392 KiB
58Elfogadva226ms104960 KiB
59Elfogadva256ms106780 KiB
60Elfogadva259ms107340 KiB
61Elfogadva114ms94960 KiB
62Elfogadva286ms115276 KiB
63Elfogadva115ms95252 KiB
64Időlimit túllépés425ms117120 KiB
65Elfogadva119ms96496 KiB
66Elfogadva115ms95444 KiB
67Elfogadva115ms95860 KiB
68Elfogadva111ms94336 KiB
69Elfogadva307ms109528 KiB
70Időlimit túllépés477ms42392 KiB