#P6384. 『MdOI R2』Quo Vadis
『MdOI R2』Quo Vadis
Background
“It’s finally… finally time to say goodbye.”
“Alright. After this time, maybe we will never meet again…”
“No matter what, we still have to part…”
“I understand you. Thank you for staying by my side these days.”
“Me too. If possible, I really wish I could keep staying with you.”
“After we part, I won’t be the me I am now…”
“At least, not like now.”
“After leaving you, I also won’t be like I am now…”
“Where are you going? Where do you want to go? Don’t go, don’t go! If you must go, please take me with you!”
…
“So… so what should we do now?”
“Then let us sing and dance in it!”
The sound of a violin and an accordion rang in my ears. It was so familiar, yet so unfamiliar…
Problem Description
Before Little M left, he left Little K a note—
If you can finish what he said, there may be a chance that I will meet you again.
You are given an infinite matrix , where .
Then there are operations. Each line contains to integers, with the following meanings:
: Perform Gaussian elimination on matrix to make it an upper triangular matrix.
Note: Here, in Gaussian elimination, you are only allowed to add a multiple of one row to another row. You are not allowed to swap any two rows, and you are not allowed to multiply any row by a constant. It is guaranteed that an upper triangular matrix can still be obtained in this way, and it is guaranteed that after elimination, every element of the matrix is a non-negative integer.
: Output the current .
: Output .
: Let be an matrix with . You need to output .
All answers above are taken modulo .
If you do not know what a determinant is, please click here. Here, means taking the determinant of a matrix.
After you finish the task that Little M gave to Little K, you can come and look at the sheet music for the violin and accordion.
Input Format
The first line contains an integer .
The next lines each contain integers, representing an operation.
Output Format
Output several lines, each being the answer modulo .
6
4 4
2 4 4
3 4
1
2 4 4
3 4
2304
64
186
32
72
Hint
[Help and Hints]
To make it easier for contestants to test their code, this problem additionally provides two extra sample sets for contestants to use.
Sample Input 1 Sample Output 1
Sample Input 2 Sample Output 2
[Sample Explanation]
Note that the queried ranges of and are both no more than , so we use the submatrix in the top-left corner of to explain. It is easy to prove that this does not cause any impact.
Before Gaussian elimination, the matrix is $\begin{pmatrix}1&2&3&4\\2&8&6&16\\3&6&27&12\\4&16&12&64\end{pmatrix}$. After Gaussian elimination, it becomes $\begin{pmatrix}1&2&3&4\\0&4&0&8\\0&0&18&0\\0&0&0&32\end{pmatrix}$.
[Constraints]
| Subtask ID | Does operation exist | In operation before operation , | In operation after operation , | In operation before operation , | In operation after operation , | In operation , | Score |
|---|---|---|---|---|---|---|---|
| Subtask 1 | No | Does not exist | Does not exist | Does not exist | |||
| Subtask 2 | |||||||
| Subtask 3 | |||||||
| Subtask 4 | |||||||
| Subtask 5 | Yes | Does not exist | |||||
| Subtask 6 | |||||||
| Subtask 7 | |||||||
For of the testdata, . Among all operation queries before operation , does not exceed times the upper bound of each test point.
It is guaranteed that operation appears at most once.
Translated by ChatGPT 5