107412024-04-10 23:42:4842Főnökszámpypy3Időlimit túllépés 40/100472ms116684 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 = 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()
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva54ms80564 KiB
2Elfogadva280ms106888 KiB
subtask25/5
3Elfogadva52ms80924 KiB
4Elfogadva54ms81752 KiB
5Elfogadva85ms89040 KiB
6Elfogadva115ms93728 KiB
subtask310/10
7Elfogadva52ms81692 KiB
8Elfogadva64ms88000 KiB
9Elfogadva65ms89460 KiB
10Elfogadva57ms86452 KiB
11Elfogadva85ms90740 KiB
12Elfogadva90ms89780 KiB
13Elfogadva111ms94000 KiB
14Elfogadva125ms96044 KiB
subtask40/10
15Elfogadva48ms82984 KiB
16Elfogadva54ms82792 KiB
17Elfogadva107ms91660 KiB
18Elfogadva129ms95420 KiB
19Elfogadva123ms95360 KiB
20Elfogadva143ms97272 KiB
21Elfogadva150ms97884 KiB
22Időlimit túllépés421ms38480 KiB
subtask525/25
23Elfogadva81ms90192 KiB
24Elfogadva93ms91056 KiB
25Elfogadva112ms96328 KiB
26Elfogadva140ms96156 KiB
27Elfogadva202ms104748 KiB
28Elfogadva240ms105332 KiB
29Elfogadva268ms108048 KiB
30Elfogadva293ms108636 KiB
subtask60/50
31Elfogadva52ms84084 KiB
32Elfogadva273ms110160 KiB
33Elfogadva52ms80924 KiB
34Elfogadva54ms81752 KiB
35Elfogadva85ms89040 KiB
36Elfogadva115ms93728 KiB
37Elfogadva52ms81692 KiB
38Elfogadva64ms88000 KiB
39Elfogadva65ms89460 KiB
40Elfogadva57ms86452 KiB
41Elfogadva85ms90740 KiB
42Elfogadva90ms89780 KiB
43Elfogadva111ms94000 KiB
44Elfogadva125ms96044 KiB
45Elfogadva48ms82984 KiB
46Elfogadva54ms82792 KiB
47Elfogadva107ms91660 KiB
48Elfogadva129ms95420 KiB
49Elfogadva123ms95360 KiB
50Elfogadva143ms97272 KiB
51Elfogadva150ms97884 KiB
52Időlimit túllépés421ms38480 KiB
53Elfogadva81ms90192 KiB
54Elfogadva93ms91056 KiB
55Elfogadva112ms96328 KiB
56Elfogadva140ms96156 KiB
57Elfogadva202ms104748 KiB
58Elfogadva240ms105332 KiB
59Elfogadva268ms108048 KiB
60Elfogadva293ms108636 KiB
61Elfogadva125ms96388 KiB
62Elfogadva300ms116684 KiB
63Elfogadva125ms96948 KiB
64Időlimit túllépés437ms116480 KiB
65Elfogadva130ms98008 KiB
66Elfogadva126ms96712 KiB
67Elfogadva119ms97152 KiB
68Elfogadva120ms96100 KiB
69Elfogadva337ms111104 KiB
70Időlimit túllépés472ms42116 KiB