107352024-04-10 23:26:2742Főnökszámpypy3Időlimit túllépés 40/100469ms118888 KiB
from sys import stdin
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)
        print(len(L))
        
main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva46ms80344 KiB
2Elfogadva296ms115460 KiB
subtask25/5
3Elfogadva45ms80832 KiB
4Elfogadva48ms80992 KiB
5Elfogadva82ms88084 KiB
6Elfogadva119ms94596 KiB
subtask310/10
7Elfogadva45ms81268 KiB
8Elfogadva57ms88320 KiB
9Elfogadva71ms89872 KiB
10Elfogadva68ms87192 KiB
11Elfogadva96ms91404 KiB
12Elfogadva97ms91048 KiB
13Elfogadva122ms96272 KiB
14Elfogadva136ms95688 KiB
subtask40/10
15Elfogadva54ms82588 KiB
16Elfogadva54ms83304 KiB
17Elfogadva93ms91116 KiB
18Elfogadva123ms95700 KiB
19Elfogadva128ms97312 KiB
20Elfogadva156ms99188 KiB
21Elfogadva180ms99240 KiB
22Időlimit túllépés469ms42888 KiB
subtask525/25
23Elfogadva75ms92048 KiB
24Elfogadva89ms92648 KiB
25Elfogadva120ms97356 KiB
26Elfogadva127ms98216 KiB
27Elfogadva207ms106960 KiB
28Elfogadva250ms113888 KiB
29Elfogadva282ms116292 KiB
30Elfogadva286ms116204 KiB
subtask60/50
31Elfogadva45ms84388 KiB
32Elfogadva305ms118888 KiB
33Elfogadva45ms80832 KiB
34Elfogadva48ms80992 KiB
35Elfogadva82ms88084 KiB
36Elfogadva119ms94596 KiB
37Elfogadva45ms81268 KiB
38Elfogadva57ms88320 KiB
39Elfogadva71ms89872 KiB
40Elfogadva68ms87192 KiB
41Elfogadva96ms91404 KiB
42Elfogadva97ms91048 KiB
43Elfogadva122ms96272 KiB
44Elfogadva136ms95688 KiB
45Elfogadva54ms82588 KiB
46Elfogadva54ms83304 KiB
47Elfogadva93ms91116 KiB
48Elfogadva123ms95700 KiB
49Elfogadva128ms97312 KiB
50Elfogadva156ms99188 KiB
51Elfogadva180ms99240 KiB
52Időlimit túllépés469ms42888 KiB
53Elfogadva75ms92048 KiB
54Elfogadva89ms92648 KiB
55Elfogadva120ms97356 KiB
56Elfogadva127ms98216 KiB
57Elfogadva207ms106960 KiB
58Elfogadva250ms113888 KiB
59Elfogadva282ms116292 KiB
60Elfogadva286ms116204 KiB
61Elfogadva126ms98028 KiB
62Elfogadva264ms105756 KiB
63Elfogadva126ms97548 KiB
64Időlimit túllépés462ms42724 KiB
65Elfogadva129ms97344 KiB
66Elfogadva123ms97076 KiB
67Elfogadva125ms98548 KiB
68Elfogadva123ms98088 KiB
69Elfogadva326ms117252 KiB
70Időlimit túllépés462ms43684 KiB