A14434 | The Three Little Pigs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Three little pigs from all over the world are meeting for a convention! Every minute, a triple of 3 new pigs arrives on the convention floor. After the $n$ -th minute, the convention ends.
The big bad wolf has learned about this convention, and he has an attack plan. At some minute in the convention, he will arrive and eat exactly $x$ pigs. Then he will get away.
The wolf wants Gregor to help him figure out the number of possible attack plans that involve eating exactly $x$ pigs for various values of $x$ ( $1 \le x \le 3n$ ). Two attack plans are considered different, if they occur at different times or if the sets of little pigs to eat are different.
Note that all queries are independent, that is, the wolf does not eat the little pigs, he only makes plans!
The big bad wolf has learned about this convention, and he has an attack plan. At some minute in the convention, he will arrive and eat exactly $x$ pigs. Then he will get away.
The wolf wants Gregor to help him figure out the number of possible attack plans that involve eating exactly $x$ pigs for various values of $x$ ( $1 \le x \le 3n$ ). Two attack plans are considered different, if they occur at different times or if the sets of little pigs to eat are different.
Note that all queries are independent, that is, the wolf does not eat the little pigs, he only makes plans!
输入格式
The first line of input contains two integers $n$ and $q$ ( $1 \le n \le 10^6$ , $1 \le q \le 2\cdot 10^5$ ), the number of minutes the convention lasts and the number of queries the wolf asks.
Each of the next $q$ lines contains a single integer $x_i$ ( $1 \le x_i \le 3n$ ), the number of pigs the wolf will eat in the $i$ -th query.
Each of the next $q$ lines contains a single integer $x_i$ ( $1 \le x_i \le 3n$ ), the number of pigs the wolf will eat in the $i$ -th query.
输出格式
You should print $q$ lines, with line $i$ representing the number of attack plans if the wolf wants to eat $x_i$ pigs. Since each query answer can be large, output each answer modulo $10^9+7$ .
输入输出样例
输入 #1
2 3 1 5 6
输出 #1
9 6 1
输入 #2
5 4 2 4 6 8
输出 #2
225 2001 6014 6939
In the example test, $n=2$ . Thus, there are $3$ pigs at minute $1$ , and $6$ pigs at minute $2$ . There are three queries: $x=1$ , $x=5$ , and $x=6$ .
If the wolf wants to eat $1$ pig, he can do so in $3+6=9$ possible attack plans, depending on whether he arrives at minute $1$ or $2$ .
If the wolf wants to eat $5$ pigs, the wolf cannot arrive at minute $1$ , since there aren't enough pigs at that time. Therefore, the wolf has to arrive at minute $2$ , and there are $6$ possible attack plans.
If the wolf wants to eat $6$ pigs, his only plan is to arrive at the end of the convention and devour everybody.
Remember to output your answers modulo $10^9+7$ !
If the wolf wants to eat $1$ pig, he can do so in $3+6=9$ possible attack plans, depending on whether he arrives at minute $1$ or $2$ .
If the wolf wants to eat $5$ pigs, the wolf cannot arrive at minute $1$ , since there aren't enough pigs at that time. Therefore, the wolf has to arrive at minute $2$ , and there are $6$ possible attack plans.
If the wolf wants to eat $6$ pigs, his only plan is to arrive at the end of the convention and devour everybody.
Remember to output your answers modulo $10^9+7$ !
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted