luogu#P8292. [省选联考 2022] 卡牌

    ID: 7637 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>各省省选2022O2优化容斥原理快速沃尔什变换 FWT

[省选联考 2022] 卡牌

Problem Description

Little A has nn cards, numbered 1,2,,n1, 2, \ldots, n. Each card has a positive integer written on it, and the positive integer on the ii-th card is sis_i.

Now there are mm rounds of games. In the ii-th round, cic_i primes are given. Little A needs to choose any number of cards such that the product of the positive integers on these chosen cards is divisible by every prime given in that round.

This is not hard for Little A, so he starts thinking about a harder problem: for each round, how many different ways are there to choose cards.

Little A cannot figure it out, so he asks you for help. You only need to output the answer modulo 998244353998244353. Two selections AA and BB are different if and only if there exists a card that is chosen in AA but not in BB, or there exists a card that is chosen in BB but not in AA. Note: two cards with the same number written on them but different indices are considered different cards.

Input Format

The first line contains a positive integer nn, indicating the number of cards.

The second line contains nn positive integers sis_i, indicating the number written on each card.

The third line contains a positive integer mm, indicating the number of rounds.

The next mm lines describe the rounds. In each line, the first positive integer is cic_i, indicating the number of primes given in that round, followed by cic_i primes pi,jp_{i, j}, indicating all primes given in that round. The testdata guarantees that ici18000\sum_i c_i \le 18000, i.e., the sum of all cic_i does not exceed 1800018000.

Output Format

Output mm lines. Each line contains one integer. The ii-th line is the number of valid selections for the ii-th round modulo 998244353998244353.

5
10 2 10 5 46
4
2 2 5
2 2 23
1 3
1 23
27
16
0
16
见附件中的 card/card2.in
见附件中的 card/card2.ans

Hint

[Sample Explanation #1]

Round 1: Except for the following 55 selections, all other selections are valid: selecting nothing, selecting 22, selecting 55, selecting 4646, selecting 22 and 4646. Therefore, the answer is 255=272^5 - 5 = 27.

Round 2: As long as 4646 is selected, it does not matter whether other cards are selected, so the answer is 24=162^4 = 16.

[Constraints]

For 100%100 \% of the testdata, 1n1061 \le n \le {10}^6, 1si20001 \le s_i \le 2000, 1m15001 \le m \le 1500, 1ci,ici180001 \le c_i, \sum_i c_i \le 18000, 2pi,j20002 \le p_{i, j} \le 2000.

Test Point nn \le mm \le ici\sum_i c_i \le Other Constraints
121 \sim 2 1010 1010 2020 si30s_i \le 30
353 \sim 5 2020 5050 None
686 \sim 8 106{10}^6 15001500 1000010000 si30s_i \le 30
9119 \sim 11 1000010000 10001000 50005000 si500s_i \le 500
121312 \sim 13 10001000 100100 10001000 None
141714 \sim 17 50005000 600600 70007000
182018 \sim 20 106{10}^6 15001500 1800018000

Translated by ChatGPT 5