CF1548C.The Three Little Pigs

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn-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 xx 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 xx pigs for various values of xx (1≤x≤3n1 \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!

来自世界各地的三只小猪正在举行一场大会!每分钟,都会有三只新小猪组成的三元组抵达大会现场。在第 nn 分钟结束后,大会结束。

大野狼得知了这场大会,并制定了一个袭击计划:他将在大会期间的某一分钟抵达,并恰好吃掉 xx 只小猪,然后迅速逃离。

野狼希望格雷戈尔帮他计算出:对于不同的 xx 值(1≤x≤3n1 \le x \le 3n),有多少种可能的袭击计划恰好吃掉 xx 只小猪。若两个袭击计划发生的时间不同,或被吃掉的小猪集合不同,则视为不同的袭击计划。

注意:所有查询相互独立,即野狼并不会真正吃掉小猪,他只是在制定计划!

输入格式

The first line of input contains two integers nn and qq (1≤n≤1061 \le n \le 10^6, 1≤q≤2⋅1051 \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 qq lines contains a single integer xix_i (1≤xi≤3n1 \le x_i \le 3n), the number of pigs the wolf will eat in the ii-th query.

输入的第一行包含两个整数 nn 和 qq(1≤n≤1061 \le n \le 10^6,1≤q≤2⋅1051 \le q \le 2\cdot 10^5),分别表示大会持续的分钟数以及狼提出的查询次数。

接下来的 qq 行中,每行包含一个整数 xix_i(1≤xi≤3n1 \le x_i \le 3n),表示在第 ii 次查询中狼将要吃的猪的数量。

输出格式

You should print qq lines, with line ii representing the number of attack plans if the wolf wants to eat xix_i pigs. Since each query answer can be large, output each answer modulo 109+710^9+7.

你需要输出 qq 行,其中第 ii 行表示狼想要吃掉 xix_i 只小猪时的攻击方案数。由于每个查询的答案可能很大,请对每个答案取模 109+710^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=2n=2. Thus, there are 33 pigs at minute 11, and 66 pigs at minute 22. There are three queries: x=1x=1, x=5x=5, and x=6x=6.

If the wolf wants to eat 11 pig, he can do so in 3+6=93+6=9 possible attack plans, depending on whether he arrives at minute 11 or 22.

If the wolf wants to eat 55 pigs, the wolf cannot arrive at minute 11, since there aren't enough pigs at that time. Therefore, the wolf has to arrive at minute 22, and there are 66 possible attack plans.

If the wolf wants to eat 66 pigs, his only plan is to arrive at the end of the convention and devour everybody.

Remember to output your answers modulo 109+710^9+7!

在样例测试中,n=2n=2。因此,第 11 分钟有 33 头猪,第 22 分钟有 66 头猪。共有三个查询:x=1x=1、x=5x=5 和 x=6x=6。

若狼想吃掉 11 头猪,则他可以在第 11 分钟或第 22 分钟抵达,对应 3+6=93+6=9 种可能的攻击方案。

若狼想吃掉 55 头猪,则他无法在第 11 分钟抵达(因为此时猪的数量不足)。因此,狼必须在第 22 分钟抵达,此时有 66 种可能的攻击方案。

若狼想吃掉 66 头猪,则他唯一的方案是在大会结束时抵达并吞食所有猪。

注意:请将答案对 109+710^9+7 取模后输出!

输入解题思路,AI测评打分。不知道怎么写?

首页