A834 | Cowmistry--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
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. In particular, two cow-michals with labels
$a$ and $b$ can only be present in the same mixture if $a \oplus b \le K$ ($1
\le K \le 10^9$).
NOTE: Here, $a\oplus 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,
$$0\oplus 0=1\oplus 1=0,$$
$$1\oplus 0=0\oplus 1=1,$$
$$5\oplus 7=101_2\oplus 111_2=010_2=2.$$
Bessie has $N$ ($1\le N\le 2\cdot 10^4$) boxes of cow-michals and the $i$-th
box contains cow-michals labeled $l_i$ through $r_i$ inclusive $(0\le l_i \le
r_i \le 10^9)$. 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
$10^9 + 7$.
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. In particular, two cow-michals with labels
$a$ and $b$ can only be present in the same mixture if $a \oplus b \le K$ ($1
\le K \le 10^9$).
NOTE: Here, $a\oplus 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,
$$0\oplus 0=1\oplus 1=0,$$
$$1\oplus 0=0\oplus 1=1,$$
$$5\oplus 7=101_2\oplus 111_2=010_2=2.$$
Bessie has $N$ ($1\le N\le 2\cdot 10^4$) boxes of cow-michals and the $i$-th
box contains cow-michals labeled $l_i$ through $r_i$ inclusive $(0\le l_i \le
r_i \le 10^9)$. 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
$10^9 + 7$.
输入格式
The first line contains two integers $N$ and $K$.
Each of the next $N$ lines contains two space-separated integers $l_i$ and
$r_i$. It is guaranteed that the boxes of cow-michals are provided in
increasing order of their contents; namely, $r_i<l_{i+1}$ for each $1\le i<N$.
Each of the next $N$ lines contains two space-separated integers $l_i$ and
$r_i$. It is guaranteed that the boxes of cow-michals are provided in
increasing order of their contents; namely, $r_i<l_{i+1}$ for each $1\le i<N$.
输出格式
The number of mixtures of three different cow-michals Bessie can create,
modulo $10^9 + 7$.
modulo $10^9 + 7$.
输入输出样例
输入 #1
1 13 0 199
输出 #1
4280
We can split the chemicals into 13 groups that cannot cross-mix: $(0\ldots
15)$, $(16\ldots 31)$, $\ldots$ $(192\ldots 199)$. Each of the first twelve
groups contributes $352$ unique mixtures and the last contributes $56$ (since
all $\binom{8}{3}$ combinations of three different cow-michals from
$(192\ldots 199)$ are okay), for a total of $352\cdot 12+56=4280$.
15)$, $(16\ldots 31)$, $\ldots$ $(192\ldots 199)$. Each of the first twelve
groups contributes $352$ unique mixtures and the last contributes $56$ (since
all $\binom{8}{3}$ combinations of three different cow-michals from
$(192\ldots 199)$ are okay), for a total of $352\cdot 12+56=4280$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted