#P6728. [COCI 2015/2016 #5] PODNIZOVI
[COCI 2015/2016 #5] PODNIZOVI
Description
Given an array of length . Let be all non-empty subsequences of this array, where .
About lexicographical order: if the first position where two arrays and differ is , and ; or is a strict prefix of (i.e., they cannot be equal), then is lexicographically smaller than .
We define the hash value of an array consisting of as:
$$h(s)=(v_1\times B^{p-1}+v_2\times B^{p-2}+\dots +v_{p-1}\times B+v_p) \bmod M$$where are given integers.
For a given integer , find the values of .
Input Format
The first line contains four integers .
The second line contains integers .
Output Format
Output a total of lines. The -th line should be the value of .
2 3 1 5
1 2
1
3
2
3 4 2 3
1 3 1
1
1
0
2
5 6 23 1000
1 2 4 2 3
1
25
25
577
274
578
Hint
Sample Explanation
Sample
.
$h(s_1) = 1 \bmod 5 = 1, h(s_2) =(1 + 2) \bmod 5 = 3, h(s_3) = 2 \bmod 5 = 2$.
Sample
.
$h(s1) = 1 \bmod 3 = 1, h(s_2) = 1 \bmod 3 = 1, h(s_3) = (1 \times 2 + 1) \bmod 3 = 0, h(s_4) = (1 \times 2 + 3) \bmod 3 = 2$.
Constraints
For of the testdata, .
For of the testdata, , , and .
Notes
Translated from COCI2015-2016 CONTEST #5 T6 PODNIZOVI。
Translated by ChatGPT 5
京公网安备 11011102002149号