Cowmistry
Time limit1sMemory limit512 MB
Count the sets of three distinct labels, taken from N disjoint integer intervals, where every pair has XOR at most K, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Divide and conquer, Combinatorics
- Solved
- No attempts yet
Problem
Bessie has been procrastinating on her cow-mistry homework and now needs your help! She needs to create a mixture of three different cow-michals. As all good cows know, though, some cow-michals cannot be mixed with each other, or else they will cause an explosion. Two cow-michals with labels and can only be present in the same mixture if ().
NOTE: Here, denotes the bitwise exclusive or of non-negative integers and . This operation adds each corresponding pair of bits in base 2 and discards the carry. For example,
Bessie has () boxes of cow-michals. The -th box contains cow-michals labeled through inclusive (). No two boxes share a cow-michal. She wants to know how many unique mixtures of three different cow-michals she can create. Two mixtures are different if at least one cow-michal is present in one but not the other. Since the answer may be very large, report it modulo .
Input
The first line contains two integers and .
Each of the next lines contains two space-separated integers and . The boxes are given in increasing order of their contents, so for each .
Output
Print the number of mixtures of three different cow-michals Bessie can create, modulo .