Task
You are given two sequences, of size and of size , both indexed from . A matrix of rows and columns is constructed where . The operation for natural numbers and refers to the bitwise OR operation. The operation is performed as follows: the numbers and are written in base , and the number has bit active if and only if either has the respective bit active or has the respective bit active.
You are given queries of the form: given a submatrix, calculate the sum of the values in it.
Note: In C++, the bitwise OR operation can be implemented as "".
Input data
The input is read from the file matmare.in
. The first line contains , , . The second line contains the sequence of elements. The third line contains the sequence of elements.
The next lines each contain four values , , , , representing a query about the submatrix between rows and and columns and .
Output data
The output will be written to the file matmare.out
. It will contain lines, each containing a single number: the sum of the submatrix for the -th query.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 20 | |
2 | 20 | |
3 | 40 | |
4 | 20 | No additional constraints |
Example
matmare.in
3 4 2
1 4 3
4 6 1 0
1 1 3 4
1 2 3 3
matmare.out
53
29
Explanation
The resulting matrix is as follows:
5 7 1 1
4 6 5 4
7 7 3 3
For the first query, the sum of the elements in the entire matrix is .
For the second query, the sum of the elements in the submatrix is .