Submission #71508998


Source Code Expand

def main():
    MAX = 10**5  # Max size of array
    tree = [0] * (4 * MAX)  # Segment tree
    lazy = [0] * (4 * MAX)  # Lazy array

    # Function to update the segment tree
    def updateRange(node, start, end, l, r, val):
        # If lazy[node] is non-zero, then there are some
        # pending updates. So we need to make sure the node is
        # updated
        if lazy[node] != 0:
            # Updating the node
            tree[node] = (end - start + 1) * lazy[node]

            # Passing the update information to its children
            if start != end:
                lazy[node * 2] = lazy[node]
                lazy[node * 2 + 1] = lazy[node]

            # Resetting the lazy value for the current node
            lazy[node] = 0

        # Out of range
        if start > end or start > r or end < l:
            return

        # Current segment is fully in range
        if start >= l and end <= r:
            # Update the node
            tree[node] = (end - start + 1) * val

            # Pass the update information to its children
            if start != end:
                lazy[node * 2] = val
                lazy[node * 2 + 1] = val
            return

        # If not completely in range but overlaps, recur for children
        mid = (start + end) // 2
        updateRange(node * 2, start, mid, l, r, val)
        updateRange(node * 2 + 1, mid + 1, end, l, r, val)

        # Use the result of children calls to update this node
        tree[node] = tree[node * 2] + tree[node * 2 + 1]

    # Function to calculate the sum on a given range
    def queryRange(node, start, end, l, r):
        # Out of range
        if start > end or start > r or end < l:
            return 0

        # If there are pending updates
        if lazy[node] != 0:
            # Updating the node
            tree[node] = (end - start + 1) * lazy[node]

            # Passing the update information to its children
            if start != end:
                lazy[node * 2] = lazy[node]
                lazy[node * 2 + 1] = lazy[node]

            # Resetting the lazy value for the current node
            lazy[node] = 0

        # At this point, we are sure that pending lazy updates
        # are done for the current node. So we can return the value
        if start >= l and end <= r:
            return tree[node]

        # If not completely in range but overlaps, recur for children
        mid = (start + end) // 2
        p1 = queryRange(node * 2, start, mid, l, r)
        p2 = queryRange(node * 2 + 1, mid + 1, end, l, r)

        # Use the result of children calls to update this node
        return p1 + p2
    N, Q = map(int, input().split())
    queries = [list(map(int, input().split())) for _ in range(Q)]

    for l, r in queries:
        updateRange(1, 0, MAX - 1, l, r, 1)
        blacks = queryRange(1, 0, N-1, 0, N-1)
        print(N - blacks)

    
main()

Submission Info

Submission Time
Task E - Cover query
User scrblbug
Language Python (PyPy 3.11-v7.3.20)
Score 0
Code Size 2989 Byte
Status WA
Exec Time 810 ms
Memory 149096 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 1
WA × 1
AC × 4
WA × 38
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
Case Name Status Exec Time Memory
example_00.txt AC 58 ms 86388 KiB
example_01.txt WA 58 ms 86312 KiB
hand_00.txt WA 434 ms 136148 KiB
hand_01.txt WA 425 ms 136316 KiB
hand_02.txt WA 423 ms 136068 KiB
hand_03.txt WA 427 ms 136192 KiB
hand_04.txt WA 426 ms 136200 KiB
hand_05.txt WA 423 ms 136324 KiB
hand_06.txt WA 427 ms 136316 KiB
hand_07.txt WA 795 ms 141280 KiB
hand_08.txt AC 801 ms 141060 KiB
hand_09.txt WA 425 ms 136308 KiB
hand_10.txt AC 806 ms 149096 KiB
hand_11.txt AC 810 ms 148992 KiB
random_00.txt WA 426 ms 136420 KiB
random_01.txt WA 423 ms 136024 KiB
random_02.txt WA 430 ms 136240 KiB
random_03.txt WA 428 ms 136088 KiB
random_04.txt WA 431 ms 136196 KiB
random_05.txt WA 428 ms 136156 KiB
random_06.txt WA 432 ms 136144 KiB
random_07.txt WA 427 ms 136264 KiB
random_08.txt WA 436 ms 136552 KiB
random_09.txt WA 440 ms 136588 KiB
random_10.txt WA 427 ms 136144 KiB
random_11.txt WA 427 ms 136192 KiB
random_12.txt WA 427 ms 136424 KiB
random_13.txt WA 426 ms 136152 KiB
random_14.txt WA 437 ms 136060 KiB
random_15.txt WA 432 ms 136244 KiB
random_16.txt WA 427 ms 136252 KiB
random_17.txt WA 426 ms 136204 KiB
random_18.txt WA 445 ms 136776 KiB
random_19.txt WA 434 ms 136420 KiB
random_20.txt WA 439 ms 136660 KiB
random_21.txt WA 430 ms 136260 KiB
random_22.txt WA 431 ms 136428 KiB
random_23.txt WA 436 ms 136412 KiB
random_24.txt WA 435 ms 136448 KiB
random_25.txt WA 431 ms 136192 KiB
random_26.txt WA 431 ms 136552 KiB
random_27.txt WA 429 ms 136196 KiB