#P7501. 「HMOI R1」50 块好兄弟

「HMOI R1」50 块好兄弟

Description

"My good brothers are endless, while your Zerg are dying every moment."

As a newly appointed commander who cares about the people, Polaris_Dane fully understood Commander Raynor's wisdom and decided to carry out this tactic to the end.

There are NN barracks, numbered 1,2,3N1,2,3\cdots N in order. Now you need to place them on a number line at integer points within [1,M][1,M]. Each barracks has a production range rir_i. If a barracks is placed at point x (1xM)x\ (1 \le x \le M), then it will produce good brothers on the interval [xri+1,x+ri1][x - r_i + 1, x + r_i - 1].

When type=0\rm type = 0, the production range must be completely contained in the interval [1,M][1,M]. When type=1\rm type = 1, the production range may go outside [1,M][1,M], but the barracks must be placed within [1,M][1,M].

Polaris_Dane cannot let the good brothers be too crowded, so the production ranges of any two barracks must not intersect. He wants to know how many placements satisfy this condition.

If there exists a barracks with index ii whose placement positions are different in two placements, then the two placements are considered different.

Since the answer may be very large, output the result modulo 998244353998244353.

Input Format

The first line contains three integers N,M,typeN, M, \mathrm{type}, where type{0,1}\rm type \in \{0, 1\}.

The second line contains NN integers r1,r2,r3,,rnr_1, r_2, r_3, \ldots, r_n.

Output Format

Output one integer in a single line: the required answer modulo 998244353998244353.

4 4 0
1 1 1 1
24
4 4 1
1 1 1 1
24
3 47 1
4 8 9
10940
8 100000 1
21 37 23 13 32 22 9 39
405170260

Hint

Explanation of the samples:

In Sample 1, no matter how you place the barracks, the production ranges will not overlap, so the answer is A44=24A_4^4 = 24.

In Sample 2, although the production ranges may go out of bounds, the barracks still have only 44 possible positions, so the answer is still A44=24A_4^4 = 24.


Constraints for all testdata:

  • 1N,M1061 \le N, M \le 10^6.
  • 1ri10001 \le r_i \le 1000.

This problem uses bundled tests.

No. Constraints type\rm type Score
11 N=2; M1000; ri=1N = 2;\ M \le 1000;\ r_i = 1 00 1010
22 N=2; M106; ri=1N = 2;\ M \le 10^6;\ r_i = 1
33 N40; M106; ri=1N \le 40;\ M \le 10^6;\ r_i = 1
44 No further constraints 3030
55 N,ri40N, r_i \le 40 11 2020
66 No further constraints

  • Idea: Polaris_Dane.
  • Solution: Polaris_Dane.
  • Code: Polaris_Dane.
  • Data: Polaris_Dane.

Translated by ChatGPT 5