Akuna CapitalOA #26
Minimum Chunks Required (Akuna Shang Hai )
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesBits & Math
A file contains totalPackets packets numbered 1-based. The uploaded ranges do not overlap; each contiguous range not yet uploaded can be split into any number of contiguous chunks, where each chunk length must be a non-negative integer power of 2, and the chunk start does not need to be aligned to its length. Find the minimum number of chunks still to be uploaded.
Input
The first line contains totalPackets and m; each of the next m lines contains an uploaded closed range l r. Original limits: 1≤totalPackets<10^18, 0≤m<10^5, 1≤l≤r≤totalPackets, and the ranges do not overlap.
Output
Output the minimum number of chunks that must be uploaded.
Example 1
Input:
10 2
1 2
9 10
Output:
2
Example 2
Input:
18 1
9 17
Output:
2
Example 3
Input:
1 0
Output:
1
Editorial
Loading solution…