#P7156. [USACO20DEC] Cowmistry P

    ID: 8092 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2020USACOO2优化数位 DP组合数学字典树 Trie

[USACO20DEC] Cowmistry P

Problem Description

Bessie's chemistry homework has been overdue for a long time, and now she needs your help. She needs to make a mixture using three different chemicals. All smart cows know that some chemicals cannot be mixed together, or they will explode. Specifically, two chemicals labeled aa and bb can appear in the same mixture when abKa⊕b≤K (1K1091≤K≤10^9).

Note: Here, aba⊕b denotes the XOR of non-negative integers aa and bb. This operation is equivalent to adding each corresponding bit in binary and discarding carries. For example,

00=11=00⊕0=1⊕1=0

,

10=01=11⊕0=0⊕1=1

,

57=10121112=0102=25⊕7=101_2⊕111_2=010_2=2

.

Bessie has NN boxes of chemicals. The ii-th box contains chemicals with labels from lil_i to rir_i (0liri1090≤l_i≤r_i≤10^9). No two boxes contain the same chemical. She wants to know how many different mixtures she can make that consist of three different chemicals. Two mixtures are considered different if there exists at least one chemical that appears in one mixture but not the other. Since the answer may be very large, output it modulo 109+710^9+7.

Input Format

The first line contains two integers NN and KK.

The next NN lines each contain two space-separated integers lil_i and rir_i. It is guaranteed that the boxes are given in increasing order by their contents; that is, for all 1i<N1≤i<N, we have ri<li+1r_i<l_{i+1}.

Output Format

Output the number of mixtures Bessie can make using three different chemicals, modulo 109+710^9+7.

1 13
0 199
4280
6 147
1 35
48 103
125 127
154 190
195 235
240 250
267188

Hint

We can divide all chemicals into 1313 groups that cannot be mixed across groups: (015)(0 \ldots 15), (1631)(16 \ldots 31), … (192199)(192 \ldots 199). Each of the first 1212 groups contributes 352352 mixtures, and the last group contributes 5656 (because all (83)\binom{8}{3} combinations of three different chemicals in (192199)(192 \ldots 199) are valid), for a total of 35212+56=4280352 \cdot 12 + 56 = 4280.

  • Subtasks 3-4 satisfy max(K,rN)104\max(K, r_N) \le {10}^4.
  • Subtasks 5-6 satisfy K=2k1K = 2^k - 1 for some k1k \ge 1.
  • Subtasks 7-11 satisfy max(K,rN)106\max(K, r_N) \le {10}^6.
  • Subtasks 12-16 satisfy N20N \le 20.
  • Subtasks 17-21 have no additional constraints.

For all subtasks, 1N2×1041 \le N \le 2 \times {10}^4.

Problem by: Benjamin Qi.

Translated by ChatGPT 5