#P7099. Rescue Voyage
Rescue Voyage
Rescue Voyage
Fusu is trapped on Lebon planet and the rescue ship piloted by Zhuang Wenyu is racing against time to save him. The rescue operation depends on a set of wormholes located on a number line. There are n wormholes at positions \(x_1, x_2, \dots, x_n\) (given in any order). Entering any one of these wormholes will instantly transport the ship to Lebon planet.
After the spaceship reaches the number line it loses control due to the magnetic field and moves in a random walk: at every second it moves one unit left or right with equal probability.
Zhuang Wenyu has provided q initial positions on the number line where the spaceship may appear. For each initial position \(x\), if it is not already at a wormhole, it will lie between two consecutive wormholes, say at positions \(a\) and \(b\) (with \(a < x < b\)). It is a classical result for the symmetric random walk with absorbing barriers that the expected time to hit either barrier is given by:
[ E(x)= (x - a)(b - x) ]
All wormhole positions are chosen so that the spaceship always starts between two wormholes (or exactly at a wormhole, yielding an expected time of 0). If the computed expected time is a fraction \(\frac{p}{q}\), you should output its value modulo 998244353 by computing \(p \times q^{-1} \bmod 998244353\), where \(q^{-1}\) is the modular multiplicative inverse of \(q\) modulo 998244353. (In our problem the expected time will always be an integer.)
Finally, instead of outputting individual answers for each query, you are required to output four integers (all modulo 998244353):
- The bitwise XOR of all answers.
- The count of answers that are odd.
- The maximum answer among all queries.
- The minimum answer among all queries.
Help Zhuang Wenyu compute these values so his rescue mission can succeed!
inputFormat
The first line contains two integers n and q (\(2 \le n \le 10^5\), \(1 \le q \le 10^5\)), representing the number of wormholes and the number of queries.
The second line contains n integers \(x_1, x_2, \dots, x_n\) (\(|x_i| \le 10^9\)), the positions of the wormholes. It is guaranteed that the wormholes are distinct and the spaceship will always start within the range \([\min{x_i}, \max{x_i}]\) for each query.
The third line contains q integers, each representing an initial coordinate of the spaceship on the number line.
outputFormat
Output four integers separated by spaces:
- The bitwise XOR of all answers (each answer taken modulo 998244353).
- The count of answers that are odd.
- The maximum answer.
- The minimum answer.
All values are computed modulo 998244353.
sample
3 4
1 4 7
1 3 4 6
0 0 2 0