
USACO 2020 December Contest, Platinum
Problem 3. Cowmistry
Contest has ended.

Log in to allow submissions in analysis mode
NOTE: Here, a⊕b denotes the "bitwise exclusive or'' of non-negative integers a and b. This operation is equivalent to adding each corresponding pair of bits in base 2 and discarding the carry. For example,
Bessie has N (1≤N≤2⋅104) boxes of cow-michals and the i-th box contains cow-michals labeled li through ri inclusive (0≤li≤ri≤109). No two boxes have any cow-michals in common. She wants to know how many unique mixtures of three different cow-michals she can create. Two mixtures are considered different if there is at least one cow-michal present in one but not the other. Since the answer may be very large, report it modulo 109+7.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains two integers N and K.Each of the next N lines contains two space-separated integers li and ri. It is guaranteed that the boxes of cow-michals are provided in increasing order of their contents; namely, ri<li+1 for each 1≤i<N.
OUTPUT FORMAT (print output to the terminal / stdout):
The number of mixtures of three different cow-michals Bessie can create, modulo 109+7.SAMPLE INPUT:
1 13 0 199
SAMPLE OUTPUT:
4280
We can split the chemicals into 13 groups that cannot cross-mix: (0…15), (16…31), … (192…199). Each of the first twelve groups contributes 352 unique mixtures and the last contributes 56 (since all (83) combinations of three different cow-michals from (192…199) are okay), for a total of 352⋅12+56=4280.
SAMPLE INPUT:
6 147 1 35 48 103 125 127 154 190 195 235 240 250
SAMPLE OUTPUT:
267188
SCORING
- Test cases 3-4 satisfy max(K,rN)≤104.
- Test cases 5-6 satisfy K=2k−1 for some integer k≥1.
- Test cases 7-11 satisfy max(K,rN)≤106.
- Test cases 12-16 satisfy N≤20.
- Test cases 17-21 satisfy no additional constraints.
Problem credits: Benjamin Qi