107372024-04-10 23:30:2642Főnökszámpypy3Wrong answer 0/100486ms118584 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 = 700

    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 = [int(x) for x in input().split()]
    L.insert((A,-B))
    print(1)

    for _ in range(N-1):
        A,B = [int(x) for x in 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)))
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer52ms80492 KiB
2Wrong answer272ms106904 KiB
subtask20/5
3Wrong answer52ms80712 KiB
4Wrong answer54ms81508 KiB
5Wrong answer83ms88372 KiB
6Wrong answer115ms93600 KiB
subtask30/10
7Wrong answer52ms82068 KiB
8Wrong answer59ms88280 KiB
9Wrong answer70ms89936 KiB
10Wrong answer65ms87016 KiB
11Wrong answer92ms90728 KiB
12Wrong answer90ms89544 KiB
13Wrong answer115ms94068 KiB
14Wrong answer119ms94744 KiB
subtask40/10
15Wrong answer52ms82856 KiB
16Wrong answer54ms82584 KiB
17Wrong answer92ms90696 KiB
18Wrong answer112ms94104 KiB
19Wrong answer115ms94508 KiB
20Wrong answer137ms97100 KiB
21Wrong answer138ms97304 KiB
22Time limit exceeded486ms40632 KiB
subtask50/25
23Wrong answer75ms90200 KiB
24Wrong answer82ms90884 KiB
25Wrong answer108ms96232 KiB
26Wrong answer112ms95188 KiB
27Wrong answer187ms104720 KiB
28Wrong answer222ms107488 KiB
29Wrong answer250ms110064 KiB
30Wrong answer254ms109684 KiB
subtask60/50
31Wrong answer52ms83776 KiB
32Wrong answer272ms110368 KiB
33Wrong answer52ms80712 KiB
34Wrong answer54ms81508 KiB
35Wrong answer83ms88372 KiB
36Wrong answer115ms93600 KiB
37Wrong answer52ms82068 KiB
38Wrong answer59ms88280 KiB
39Wrong answer70ms89936 KiB
40Wrong answer65ms87016 KiB
41Wrong answer92ms90728 KiB
42Wrong answer90ms89544 KiB
43Wrong answer115ms94068 KiB
44Wrong answer119ms94744 KiB
45Wrong answer52ms82856 KiB
46Wrong answer54ms82584 KiB
47Wrong answer92ms90696 KiB
48Wrong answer112ms94104 KiB
49Wrong answer115ms94508 KiB
50Wrong answer137ms97100 KiB
51Wrong answer138ms97304 KiB
52Time limit exceeded486ms40632 KiB
53Wrong answer75ms90200 KiB
54Wrong answer82ms90884 KiB
55Wrong answer108ms96232 KiB
56Wrong answer112ms95188 KiB
57Wrong answer187ms104720 KiB
58Wrong answer222ms107488 KiB
59Wrong answer250ms110064 KiB
60Wrong answer254ms109684 KiB
61Wrong answer122ms95460 KiB
62Wrong answer270ms111096 KiB
63Wrong answer123ms96624 KiB
64Time limit exceeded426ms118584 KiB
65Wrong answer115ms95536 KiB
66Wrong answer114ms97056 KiB
67Wrong answer114ms96928 KiB
68Wrong answer111ms95404 KiB
69Wrong answer305ms112120 KiB
70Time limit exceeded467ms41688 KiB