#P5300. [GXOI/GZOI2019] 与或和
[GXOI/GZOI2019] 与或和
Description
After learning bitwise operations and matrices, Freda decided to further study these simple and elegant operations, as well as the structures that contain profound spaces.
For a matrix consisting of non-negative integers, she defines the value of the matrix as the result of applying bitwise to all numbers in the matrix; she defines the value of the matrix as the result of applying bitwise to all numbers in the matrix.
Given an matrix, she wants to compute:
- The sum of the values of all submatrices (the result of adding up the values of all submatrices).
- The sum of the values of all submatrices (the result of adding up the values of all submatrices).
You can probably guess what happens next—Freda does not want to spend time solving such a simple problem, so she leaves it to you.
Since the answer may be very large, you only need to output the result modulo .
Input Format
The first line of the input file contains a positive integer , which denotes the size of the matrix.
The next lines each contain natural numbers, representing one row of the matrix. Any two adjacent natural numbers are separated by one or more spaces.
Output Format
Output a single line containing two integers separated by a space. The first should be the remainder when the sum of values of all submatrices is taken modulo , and the second should be the remainder when the sum of values of all submatrices is taken modulo .
3
1 0 0
0 0 0
0 0 0
1 9
3
1 2 3
4 5 6
7 8 9
73 314
Hint
Explanation of Sample 1
This matrix has submatrices of size , submatrices of size , submatrices of size , submatrices of size , submatrices of size , submatrices of size , submatrices of size , submatrices of size , and submatrix of size .
Only one submatrix (the matrix consisting only of the element in the first row and first column) has an value of ; all other submatrices have an value of , so the total sum is .
There are submatrices that contain the element in the first row and first column. Their value is , while all other submatrices have an value of , so the total sum is .
Constraints
| Test Point ID | Scale of | Natural numbers in the matrix |
|---|---|---|
In addition, there is a set of unscored hack testdata placed in subtask 1, with the same constraints as test points .
Translated by ChatGPT 5
京公网安备 11011102002149号