#P5472. [NOI2019] 斗主地

[NOI2019] 斗主地

Description

Xiao S is playing a game called “Dou Dizhu” with Xiao F.

Poor Xiao S finds that he cannot beat Xiao F at playing cards, so he wants to do something during the shuffling stage.

A deck has nn cards, numbered from top to bottom as 1n1 \sim n. The score of the card numbered ii is f(i)f(i). In this problem, f(i)f(i) has exactly two possibilities: f(i)=if(i) = i or f(i)=i2f(i) = i^2.

The shuffling method is similar to what we do in daily life. We define it formally as follows: the shuffling stage consists of mm rounds, performed in order. In round ii:

  1. Xiao S takes the top AiA_i cards from the deck. Then the deck is split into two piles: the first pile is the top AiA_i cards, and the second pile is the remaining nAin-A_i cards, and the relative order within each pile remains unchanged. In particular, when Ai=nA_i = n or Ai=0A_i = 0, one pile is empty.
  2. Next, merge the two piles to produce a new third pile. When the first pile has XX cards left and the second pile has YY cards left, with probability XX+Y\dfrac{X}{X+Y} take the bottom card of the first pile and put it on the top of the new third pile; with probability YX+Y\dfrac{Y}{X+Y} take the bottom card of the second pile and put it on the top of the new third pile.
  3. Repeat step 22 until both piles are empty. This completes one round of shuffling.

Because the shuffling process is random, Xiao S cannot know exactly which card is at a certain position. But after these mm rounds of shuffling, Xiao S wants to ask what the expected score of the card at a certain position is. Xiao S will ask you QQ such questions.

Input Format

The first line contains three positive integers n,m,typen, m, type, representing the number of cards, the number of shuffling rounds, and the type of f(i)f(i). When type=1type = 1, f(i)=if(i) = i. When type=2type = 2, f(i)=i2f(i) = i^2.

The next line contains mm integers, representing A1AmA_1 \sim A_m.

The next line contains a positive integer QQ, the number of queries from Xiao S. The next QQ lines each contain a positive integer cic_i, meaning Xiao S wants to know the expected score of the card at the cic_i-th position from top to bottom.

It is guaranteed that 1cin1 \leq c_i \leq n.

Output Format

Output QQ lines. Each line contains one integer, which is the answer modulo 998244353998244353.

That is, suppose the answer in lowest terms is ab\dfrac{a}{b}, where aa and bb are coprime. Output an integer xx such that bxa(mod998244353)bx \equiv a \pmod{998244353} and 0x<9982443530 \le x < 998244353. It can be proven that such an integer xx is unique.

4 1 1
3
1
1
249561090

Hint

More Samples

You can obtain more samples through the additional files.

Sample 2

See landlords/landlords2.in and landlords/landlords2.ans in the additional files.

Sample 3

See landlords/landlords3.in and landlords/landlords3.ans in the additional files.

Explanation for Sample Input/Output 1

  • With probability 14\dfrac{1}{4}, the final result from top to bottom is {1,2,3,4}\{1, 2, 3, 4\}.
  • With probability 14\dfrac{1}{4}, the final result from top to bottom is {1,2,4,3}\{1, 2, 4, 3\}.
  • With probability 14\dfrac{1}{4}, the final result from top to bottom is {1,4,2,3}\{1, 4, 2, 3\}.
  • With probability 14\dfrac{1}{4}, the final result from top to bottom is {4,1,2,3}\{4, 1, 2, 3\}.

So in the end, with probability 14\dfrac{1}{4} the first position is 44, and with probability 34\dfrac{3}{4} the first position is 11. Therefore, the expected score of the first position is 74\dfrac{7}{4}.

To help you understand the shuffling process more intuitively, we draw below the process where the result is {1,4,2,3}\{1, 4, 2, 3\}.

Constraints and Notes

For all test points, it is guaranteed that 3n1073\le n \le 10^7, 1m,Q5×1051\le m,Q\le5\times 10^5, 0Ain0\le A_i\le n, type{1,2}type\in \{1,2\}.

The specific limits for each test point are shown in the table below:

Test Point nn mm type=type= Other Properties
11 10\le 10 1\le 1 11 None
22 80\le 80
33 22
44 100\le 100 5×105\le 5\times 10^5 All AiA_i are the same
55 107\le 10^7 11 None
66
77
88 22
99
1010

Please note that we do not guarantee QnQ\le n.

Hint

Here we give the definition of the expectation E[x]\mathbb{E}[x] of a discrete random variable XX:

Suppose the possible values of XX are X1,X2,XkX_1,X_2,\ldots X_k, and Pr[X1],Pr[X2],,Pr[Xk]Pr[X_1],Pr[X_2],\ldots,Pr[X_k] are the probabilities that XX takes the corresponding values. Then the expectation of XX is:

E[x]=i=1kXi×Pr[Xi]\mathbb{E}[x]=\sum^k_{i=1}X_i\times Pr[X_i]

Translated by ChatGPT 5