#P2222. [HNOI2001] 矩阵乘积
[HNOI2001] 矩阵乘积
Description
Given matrices:
$$A_{m\times n}=\begin{bmatrix}a_{1,1} & a_{1,2} & \cdots & a_{1,n}\\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots\\ a_{m,1} & a_{m,2} & \cdots &a_{m,n} \end{bmatrix} ,B_{n\times p}=\begin{bmatrix}b_{1,1} & b_{1,2} & \cdots & b_{1,p}\\ b_{2,1} & b_{2,2} & \cdots & b_{2,p} \\ \vdots & \vdots & \ddots & \vdots\\ b_{n,1} & b_{n,2} & \cdots &b_{n,p} \end{bmatrix}$$When the number of columns of matrix equals the number of rows of matrix , then and can be multiplied. Their product is an matrix :
$$D_{m\times p}=\begin{bmatrix} d_{1,1} & d_{1,2} & \cdots & d_{1,p}\\ d_{2,1} & d_{2,2} & \cdots & d_{2,p} \\ \vdots & \vdots & \ddots & \vdots\\ d_{m,1} & d_{m,2} & \cdots & d_{m,p}\end{bmatrix}$$where , abbreviated as .
Now three matrices are given. Most elements of these matrices are ; we call such matrices sparse matrices. Therefore, we use a triple to indicate that the value at row and column is , and all other unspecified elements are . In the computer, we only give triples of nonzero elements, and we use row-major order: first give the first row in increasing column order, then the second row in increasing column order, and so on.
For example, for the matrix $\begin{bmatrix}1&0&0&0\\0&0&2&-1\\0&1&2&3\\0&0&0&0\end{bmatrix}$, its triple representation is:
1 1 1
2 3 2
2 4 -1
3 2 1
3 3 2
3 4 3
Your task is to compute .
Input Format
- The first line contains two positive integers , which are the row and column of the result to output.
- The second line contains four integers , meaning is an matrix, is an matrix, and is an matrix.
- From the third line onward, each line contains three integers that form one element in the triple representation of a matrix. There is one blank line between matrices. The order is matrices , , .
Output Format
Output a single integer: the value of the element in row , column of .
1 2
3 4 2 3
1 1 3
1 4 5
2 2 1
3 1 2
1 2 2
2 1 1
3 1 2
3 2 4
1 2 2
1 3 3
2 1 1
2 2 2
12
Hint
Constraints
- For all test points, , and the total number of triples does not exceed .
- Numbers are separated by spaces.
Translated by ChatGPT 5
京公网安备 11011102002149号