CF1251F.Red-White Fence

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Polycarp wants to build a fence near his house. He has nn white boards and kk red boards he can use to build it. Each board is characterised by its length, which is an integer.

A good fence should consist of exactly one red board and several (possibly zero) white boards. The red board should be the longest one in the fence (every white board used in the fence should be strictly shorter), and the sequence of lengths of boards should be ascending before the red board and descending after it. Formally, if mm boards are used, and their lengths are l1l_1, l2l_2, ..., lml_m in the order they are placed in the fence, from left to right (let's call this array [l1,l2,…,lm][l_1, l_2, \dots, l_m] the array of lengths), the following conditions should hold:

  • there should be exactly one red board in the fence (let its index be jj);
  • for every i∈[1,j−1]i \in [1, j - 1] li<li+1l_i \lt l_{i + 1};
  • for every i∈[j,m−1]i \in [j, m - 1] li>li+1l_i \gt l_{i + 1}.

When Polycarp will build his fence, he will place all boards from left to right on the same height of 00, without any gaps, so these boards compose a polygon:

Example: a fence with [3,5,4,2,1][3, 5, 4, 2, 1] as the array of lengths. The second board is red. The perimeter of the fence is 2020.

Polycarp is interested in fences of some special perimeters. He has qq even integers he really likes (these integers are Q1Q_1, Q2Q_2, ..., QqQ_q), and for every such integer QiQ_i, he wants to calculate the number of different fences with perimeter QiQ_i he can build (two fences are considered different if their arrays of lengths are different). Can you help him calculate these values?

波利卡普想在自家附近建造一道篱笆。他有 nn 块白色木板和 kk 块红色木板可用于建造篱笆。每块木板由其长度(一个整数)表征。

一道“合格的”篱笆必须恰好包含一块红色木板以及若干(可能为零)块白色木板。其中,红色木板必须是篱笆中最长的一块(即所有被使用的白色木板长度都必须严格小于该红色木板),且木板长度序列在红色木板之前严格递增、在红色木板之后严格递减。形式化地,若篱笆共使用 mm 块木板,其从左至右(即沿篱笆方向)的长度依次为 l1,l2,…,lml_1, l_2, \dots, l_m(我们称该序列为长度数组 [l1,l2,…,lm][l_1, l_2, \dots, l_m]),则需满足以下条件:

  • 篱笆中恰好有一块红色木板(设其下标为 jj);
  • 对任意 i∈[1,j−1]i \in [1, j - 1],有 li<li+1l_i \lt l_{i + 1};
  • 对任意 i∈[j,m−1]i \in [j, m - 1],有 li>li+1l_i \gt l_{i + 1}。

当波利卡普建造篱笆时,他会将所有木板自左向右、在同一高度(高度为 00)上紧密排列(中间无空隙),从而构成一个多边形:

示例:长度数组为 [3,5,4,2,1][3, 5, 4, 2, 1] 的篱笆。第二块木板为红色。该篱笆的周长为 2020。

波利卡普特别关注具有某些特定周长的篱笆。他有 qq 个他十分喜爱的偶数(记为 Q1,Q2,…,QqQ_1, Q_2, \dots, Q_q),对于每个这样的整数 QiQ_i,他希望计算出能建造出的、周长恰好为 QiQ_i 的不同篱笆的数量(若两道篱笆的长度数组不同,则视为不同的篱笆)。你能帮他计算这些数值吗?

输入格式

The first line contains two integers nn and kk (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5, 1≤k≤51 \le k \le 5) — the number of white and red boards Polycarp has.

The second line contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤3⋅1051 \le a_i \le 3 \cdot 10^5) — the lengths of white boards Polycarp has.

The third line contains kk integers b1b_1, b2b_2, ..., bkb_k (1≤bi≤3⋅1051 \le b_i \le 3 \cdot 10^5) — the lengths of red boards Polycarp has. All bib_i are distinct.

The fourth line contains one integer qq (1≤q≤3⋅1051 \le q \le 3 \cdot 10^5) — the number of special integers.

The fifth line contains qq integers Q1Q_1, Q2Q_2, ..., QqQ_q (4≤Qi≤12⋅1054 \le Q_i \le 12 \cdot 10^5, every QiQ_i is even) — the special integers Polycarp likes.

第一行包含两个整数 nn 和 kk(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5,1≤k≤51 \le k \le 5)—— 分别表示 Polycarp 拥有的白色木板和红色木板的数量。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(1≤ai≤3⋅1051 \le a_i \le 3 \cdot 10^5)—— 表示 Polycarp 拥有的白色木板的长度。

第三行包含 kk 个整数 b1b_1, b2b_2, ..., bkb_k(1≤bi≤3⋅1051 \le b_i \le 3 \cdot 10^5)—— 表示 Polycarp 拥有的红色木板的长度。所有 bib_i 互不相同。

第四行包含一个整数 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)—— 表示特殊整数的个数。

第五行包含 qq 个整数 Q1Q_1, Q2Q_2, ..., QqQ_q(4≤Qi≤12⋅1054 \le Q_i \le 12 \cdot 10^5,且每个 QiQ_i 均为偶数)—— 表示 Polycarp 喜欢的特殊整数。

输出格式

For each QiQ_i, print one integer — the number of good fences with perimeter QiQ_i Polycarp can build, taken modulo 998244353998244353.

对于每个 QiQ_i,输出一个整数——Polycarp 能够建造的周长为 QiQ_i 的“好”围栏的数量,结果对 998244353998244353 取模。

输入输出样例

  • 输入#1

    5 2
    3 3 1 1 1
    2 4
    7
    6 8 10 12 14 16 18

    输出#1

    1
    2
    2
    4
    6
    4
    1
  • 输入#2

    5 5
    1 2 3 4 5
    1 2 3 4 5
    4
    4 8 10 14

    输出#2

    1
    3
    5
    20

说明/提示

Possible fences in the first example denoted by their arrays of lengths (the length of the red board is highlighted):

  • with perimeter 66: [2][\textbf{2}];
  • with perimeter 88: [1,2][1, \textbf{2}], [2,1][\textbf{2}, 1];
  • with perimeter 1010: [1,2,1][1, \textbf{2}, 1], [4][\textbf{4}];
  • with perimeter 1212: [1,4][1, \textbf{4}], [3,4][3, \textbf{4}], [4,1][\textbf{4}, 1], [4,3][\textbf{4}, 3];
  • with perimeter 1414: [1,4,1][1, \textbf{4}, 1], [1,4,3][1, \textbf{4}, 3], [3,4,1][3, \textbf{4}, 1], [3,4,3][3, \textbf{4}, 3], [1,3,4][1, 3, \textbf{4}], [4,3,1][\textbf{4}, 3, 1];
  • with perimeter 1616: [1,4,3,1][1, \textbf{4}, 3, 1], [3,4,3,1][3, \textbf{4}, 3, 1], [1,3,4,1][1, 3, \textbf{4}, 1], [1,3,4,3][1, 3, \textbf{4}, 3];
  • with perimeter 1818: [1,3,4,3,1][1, 3, \textbf{4}, 3, 1].

第一个示例中可能的围栏(以其长度数组表示,红色木板的长度已加粗标出):

  • 周长为 66:[2][\textbf{2}];
  • 周长为 88:[1,2][1, \textbf{2}],[2,1][\textbf{2}, 1];
  • 周长为 1010:[1,2,1][1, \textbf{2}, 1],[4][\textbf{4}];
  • 周长为 1212:[1,4][1, \textbf{4}],[3,4][3, \textbf{4}],[4,1][\textbf{4}, 1],[4,3][\textbf{4}, 3];
  • 周长为 1414:[1,4,1][1, \textbf{4}, 1],[1,4,3][1, \textbf{4}, 3],[3,4,1][3, \textbf{4}, 1],[3,4,3][3, \textbf{4}, 3],[1,3,4][1, 3, \textbf{4}],[4,3,1][\textbf{4}, 3, 1];
  • 周长为 1616:[1,4,3,1][1, \textbf{4}, 3, 1],[3,4,3,1][3, \textbf{4}, 3, 1],[1,3,4,1][1, 3, \textbf{4}, 1],[1,3,4,3][1, 3, \textbf{4}, 3];
  • 周长为 1818:[1,3,4,3,1][1, 3, \textbf{4}, 3, 1]。

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

首页