# 10087. Sparse Matrix Multiplication (OpenMP)

## 題目描述

$$A_{4,4} = \begin{bmatrix} 0 & 0 & 0 & 0 \\ 5 & 8 & 0 & 0 \\ 0 & 0 & 3 & 0 \\ 0 & 6 & 0 & 0 \\ \end{bmatrix}, \qquad B_{4,4} = \begin{bmatrix} 0 & 0 & 1 & 3 \\ 0 & 5 & 2 & 0 \\ 3 & 5 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ \end{bmatrix}$$

### COO of Matrix $A$

row_index col_index value
1 0 5
1 1 8
2 2 3
3 1 6

### COO of Matrix $B$

row_index col_index value
0 2 1
0 3 3
1 1 5
1 2 2
2 0 3
2 1 5
3 1 2

## 輸入格式

• $0 \lt N, \; M, \; R \le 10^6$
• $0 \lt N_A, \; N_B \le 10^6$

## 輸出格式

12345678910111213141516171819202122232425262728293031static inline uint32_t rotate_left(uint32_t x, uint32_t n) {    return  (x << n) | (x >> (32-n));}static inline uint32_t encrypt(uint32_t m, uint32_t key) {    return (rotate_left(m, key&31) + key)^key;}#define MAXN 1024uint32_t A[MAXN][MAXN], B[MAXN][MAXN];int main() {    int x, y, v;    int N, M, R, nA, nB;    scanf("%d %d %d", &N, &M, &R);    scanf("%d %d", &nA, &nB);    for (int i = 0; i < nA; i++)        scanf("%d %d %d", &x, &y, &v), A[x][y] = v;    for (int i = 0; i < nB; i++)        scanf("%d %d %d", &x, &y, &v), B[x][y] = v;     uint32_t hash = 0;    for (int i = 0; i < N; i++) {        for (int j = 0; j < R; j++) {            uint32_t sum = 0;            for (int k = 0; k < M; k++)                sum += A[i][k] * B[k][j];            if (sum)                hash += encrypt((i+1)*(j+1), sum);        }    }    printf("%u\n", hash);    return 0;}


## 範例輸入

4 4 44 7 1 0 51 1 82 2 33 1 6 0 2 10 3 31 1 51 2 22 0 32 1 53 1 2


## 範例輸出

13093438


## 範例解釋

$$A_{n, m} \times B_{m, r} = C_{4,4}=\begin{bmatrix} 0 & 0 & 0 & 0 \\ 0 & 40 & 21 & 15 \\ 9 & 15 & 0 & 0 \\ 0 & 30 & 12 & 0 \\ \end{bmatrix}$$