CF1251F.Red-White Fence
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp wants to build a fence near his house. He has n white boards and k 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 m boards are used, and their lengths are l1, l2, ..., lm in the order they are placed in the fence, from left to right (let's call this array [l1,l2,…,lm] the array of lengths), the following conditions should hold:
- there should be exactly one red board in the fence (let its index be j);
- for every i∈[1,j−1] li<li+1;
- for every i∈[j,m−1] li>li+1.
When Polycarp will build his fence, he will place all boards from left to right on the same height of 0, without any gaps, so these boards compose a polygon:
Example: a fence with [3,5,4,2,1] as the array of lengths. The second board is red. The perimeter of the fence is 20.
Polycarp is interested in fences of some special perimeters. He has q even integers he really likes (these integers are Q1, Q2, ..., Qq), and for every such integer Qi, he wants to calculate the number of different fences with perimeter Qi he can build (two fences are considered different if their arrays of lengths are different). Can you help him calculate these values?
波利卡普想在自家附近建造一道篱笆。他有 n 块白色木板和 k 块红色木板可用于建造篱笆。每块木板由其长度(一个整数)表征。
一道“合格的”篱笆必须恰好包含一块红色木板以及若干(可能为零)块白色木板。其中,红色木板必须是篱笆中最长的一块(即所有被使用的白色木板长度都必须严格小于该红色木板),且木板长度序列在红色木板之前严格递增、在红色木板之后严格递减。形式化地,若篱笆共使用 m 块木板,其从左至右(即沿篱笆方向)的长度依次为 l1,l2,…,lm(我们称该序列为长度数组 [l1,l2,…,lm]),则需满足以下条件:
- 篱笆中恰好有一块红色木板(设其下标为 j);
- 对任意 i∈[1,j−1],有 li<li+1;
- 对任意 i∈[j,m−1],有 li>li+1。
当波利卡普建造篱笆时,他会将所有木板自左向右、在同一高度(高度为 0)上紧密排列(中间无空隙),从而构成一个多边形:
示例:长度数组为 [3,5,4,2,1] 的篱笆。第二块木板为红色。该篱笆的周长为 20。
波利卡普特别关注具有某些特定周长的篱笆。他有 q 个他十分喜爱的偶数(记为 Q1,Q2,…,Qq),对于每个这样的整数 Qi,他希望计算出能建造出的、周长恰好为 Qi 的不同篱笆的数量(若两道篱笆的长度数组不同,则视为不同的篱笆)。你能帮他计算这些数值吗?
输入格式
The first line contains two integers n and k (1≤n≤3⋅105, 1≤k≤5) — the number of white and red boards Polycarp has.
The second line contains n integers a1, a2, ..., an (1≤ai≤3⋅105) — the lengths of white boards Polycarp has.
The third line contains k integers b1, b2, ..., bk (1≤bi≤3⋅105) — the lengths of red boards Polycarp has. All bi are distinct.
The fourth line contains one integer q (1≤q≤3⋅105) — the number of special integers.
The fifth line contains q integers Q1, Q2, ..., Qq (4≤Qi≤12⋅105, every Qi is even) — the special integers Polycarp likes.
第一行包含两个整数 n 和 k(1≤n≤3⋅105,1≤k≤5)—— 分别表示 Polycarp 拥有的白色木板和红色木板的数量。
第二行包含 n 个整数 a1, a2, ..., an(1≤ai≤3⋅105)—— 表示 Polycarp 拥有的白色木板的长度。
第三行包含 k 个整数 b1, b2, ..., bk(1≤bi≤3⋅105)—— 表示 Polycarp 拥有的红色木板的长度。所有 bi 互不相同。
第四行包含一个整数 q(1≤q≤3⋅105)—— 表示特殊整数的个数。
第五行包含 q 个整数 Q1, Q2, ..., Qq(4≤Qi≤12⋅105,且每个 Qi 均为偶数)—— 表示 Polycarp 喜欢的特殊整数。
输出格式
For each Qi, print one integer — the number of good fences with perimeter Qi Polycarp can build, taken modulo 998244353.
对于每个 Qi,输出一个整数——Polycarp 能够建造的周长为 Qi 的“好”围栏的数量,结果对 998244353 取模。
输入输出样例
输入#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 6: [2];
- with perimeter 8: [1,2], [2,1];
- with perimeter 10: [1,2,1], [4];
- with perimeter 12: [1,4], [3,4], [4,1], [4,3];
- with perimeter 14: [1,4,1], [1,4,3], [3,4,1], [3,4,3], [1,3,4], [4,3,1];
- with perimeter 16: [1,4,3,1], [3,4,3,1], [1,3,4,1], [1,3,4,3];
- with perimeter 18: [1,3,4,3,1].
第一个示例中可能的围栏(以其长度数组表示,红色木板的长度已加粗标出):
- 周长为 6:[2];
- 周长为 8:[1,2],[2,1];
- 周长为 10:[1,2,1],[4];
- 周长为 12:[1,4],[3,4],[4,1],[4,3];
- 周长为 14:[1,4,1],[1,4,3],[3,4,1],[3,4,3],[1,3,4],[4,3,1];
- 周长为 16:[1,4,3,1],[3,4,3,1],[1,3,4,1],[1,3,4,3];
- 周长为 18:[1,3,4,3,1]。
输入解题思路,AI测评打分。不知道怎么写?