107422024-04-10 23:51:5042Főnökszámpypy3Time limit exceeded 40/100481ms116332 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 = 50

    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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted46ms80388 KiB
2Accepted273ms106688 KiB
subtask25/5
3Accepted43ms80996 KiB
4Accepted46ms81576 KiB
5Accepted75ms88896 KiB
6Accepted107ms93232 KiB
subtask310/10
7Accepted43ms81860 KiB
8Accepted54ms86344 KiB
9Accepted67ms88204 KiB
10Accepted57ms86032 KiB
11Accepted85ms91016 KiB
12Accepted90ms89764 KiB
13Accepted111ms93796 KiB
14Accepted126ms95688 KiB
subtask40/10
15Accepted48ms82680 KiB
16Accepted46ms82532 KiB
17Accepted92ms91900 KiB
18Accepted104ms95628 KiB
19Accepted112ms95484 KiB
20Accepted130ms97228 KiB
21Accepted140ms97016 KiB
22Time limit exceeded481ms39260 KiB
subtask525/25
23Accepted71ms90072 KiB
24Accepted83ms90608 KiB
25Accepted108ms96220 KiB
26Accepted129ms96412 KiB
27Accepted190ms103608 KiB
28Accepted226ms105396 KiB
29Accepted261ms107008 KiB
30Accepted273ms108084 KiB
subtask60/50
31Accepted52ms83292 KiB
32Accepted280ms109752 KiB
33Accepted43ms80996 KiB
34Accepted46ms81576 KiB
35Accepted75ms88896 KiB
36Accepted107ms93232 KiB
37Accepted43ms81860 KiB
38Accepted54ms86344 KiB
39Accepted67ms88204 KiB
40Accepted57ms86032 KiB
41Accepted85ms91016 KiB
42Accepted90ms89764 KiB
43Accepted111ms93796 KiB
44Accepted126ms95688 KiB
45Accepted48ms82680 KiB
46Accepted46ms82532 KiB
47Accepted92ms91900 KiB
48Accepted104ms95628 KiB
49Accepted112ms95484 KiB
50Accepted130ms97228 KiB
51Accepted140ms97016 KiB
52Time limit exceeded481ms39260 KiB
53Accepted71ms90072 KiB
54Accepted83ms90608 KiB
55Accepted108ms96220 KiB
56Accepted129ms96412 KiB
57Accepted190ms103608 KiB
58Accepted226ms105396 KiB
59Accepted261ms107008 KiB
60Accepted273ms108084 KiB
61Accepted116ms96156 KiB
62Accepted284ms116332 KiB
63Accepted115ms96472 KiB
64Time limit exceeded437ms39112 KiB
65Accepted119ms97964 KiB
66Accepted115ms96636 KiB
67Accepted115ms97124 KiB
68Accepted111ms95364 KiB
69Accepted337ms111580 KiB
70Time limit exceeded474ms40612 KiB