#P11448. 「ALFR Round 3」D 核裂变
「ALFR Round 3」D 核裂变
Description
There are radioactive atoms that will undergo fission reactions for seconds. If at the beginning of the -th second, atom is bombarded by neutrons, it will release units of energy during the -th second and will release neutron to each of the atoms numbered . Thus, at the beginning of the next second (), the number of neutrons hitting each of will increase by (if , meaning this is the last second, then neutrons will not be released by bombarded atoms). If an atom is not bombarded by any neutrons at the beginning of a second, it will not release energy or neutrons.
At the beginning of each second, atoms numbered are bombarded by neutron. Therefore, from the beginning of the first second until the end of the -th second, how much energy will each atom release?
Output the answer modulo .
Input Format
The first line contains three integers , representing the number of atoms, the duration of the reaction, and the number of atoms hit each second.
The second line contains integers .
The next lines contain the information for each atom, formatted as follows:
The -th line contains integers, where the first number is , followed by integers .
Output Format
Output one line containing integers. The -th number is the total energy released by atom from the start of the -st second to the termination moment of the -th second, with the result taken modulo .
3 3 1
1
1 2
1 3
1 1
6 4 2
3 1000000000000000000 1
1
1 2
1 3
1 1
151723985 433897441 433897439
Hint
Explanation of sample #1:
- In the first second, atom is hit by neutron, releasing neutron to atom , thus releasing units of energy.
- In the second second, atom is hit by neutron, releasing neutron to atom , and releasing units of energy. Simultaneously, atom is hit by neutron, releasing neutron to atom , and releasing units of energy.
- In the third second, atom is hit by neutron, releasing units of energy. Meanwhile, atom is hit by neutron, releasing units of energy, and atom is hit by neutron, releasing units of energy.
Thus, atom releases a total of units of energy, atom releases units of energy, and atom releases units of energy.
| Subtask | Score | Constraints |
|---|---|---|
| , | ||
| - |
For all the tests, , , , , and are distinct, while are also distinct.
This problem has a large input, please use faster I/O methods.
京公网安备 11011102002149号