117462024-11-08 16:23:50balintÁruszállítás üres szakaszaipython3Time limit exceeded 12/50400ms4220 KiB
class BitRangeManager:
    # ZERO INDEXED
    def __init__(self, size):
        self.size = size
        # Initialize a single integer to represent all the bits.
        self.bit_array = 0  # Start with all bits set to 0.

    def set_range(self, start, amount):
        mask = (1 << amount) - 1
        mask <<= start
        self.bit_array |= mask

    def __repr__(self):
        """
        Return a string representation of the bit array as '1's and '0's.
        """
        # Generate the binary string representation of the large int  # pad to 'size' bits
        return f"{self.bit_array:0{self.size}b}"[::-1]


def count_zero_groups_from_int(number, bit_width=32):
    # Initialize count and the flag to track if we are in a zero group
    count = 0
    in_zero_group = False

    # Iterate over all bits of the integer, including leading zeros
    for i in range(bit_width - 1, -1, -1):  # Start from the most significant bit (MSB)
        # Check if the i-th bit is zero
        if (number & (1 << i)) == 0:
            if not in_zero_group:
                count += 1  # New group of zeros
                in_zero_group = True
        else:  # If the i-th bit is 1
            in_zero_group = False

    return count


def main():
    N, M = map(int, input().split())
    bitman = BitRangeManager(N)
    for _ in range(M):
        inp = tuple(map(int, input().split()))
        bitman.set_range(inp[0] - 1, inp[1] - inp[0] + 1)
    print(count_zero_groups_from_int(bitman.bit_array, bitman.size))


main()
SubtaskSumTestVerdictTimeMemory
base12/50
1Accepted0/017ms3124 KiB
2Time limit exceeded0/0386ms4200 KiB
3Accepted2/216ms3048 KiB
4Accepted2/216ms3120 KiB
5Wrong answer0/217ms3112 KiB
6Wrong answer0/217ms2964 KiB
7Accepted2/217ms3120 KiB
8Wrong answer0/217ms2952 KiB
9Accepted2/216ms3120 KiB
10Accepted2/217ms3132 KiB
11Accepted2/2112ms3188 KiB
12Wrong answer0/2222ms3240 KiB
13Wrong answer0/3150ms3304 KiB
14Time limit exceeded0/3388ms3384 KiB
15Time limit exceeded0/3400ms3392 KiB
16Time limit exceeded0/3377ms3876 KiB
17Time limit exceeded0/3400ms3960 KiB
18Time limit exceeded0/3377ms3844 KiB
19Time limit exceeded0/3398ms3676 KiB
20Time limit exceeded0/3381ms3960 KiB
21Time limit exceeded0/3398ms4180 KiB
22Time limit exceeded0/3386ms4220 KiB