#P16269. [蓝桥杯 2026 省 Java B 组] 量子态叠加计数器
[蓝桥杯 2026 省 Java B 组] 量子态叠加计数器
Problem Description
A quantum laboratory recorded the states of qubits at times . Each state value is or .
For any qubit and any time interval (), if the number of times the qubit’s state is within the interval is exactly , then we say the qubit produces one valid superposition in this interval.
Now, please count: among all qubits and all time intervals, the total number of valid superpositions.
Input Format
The first line contains three integers , representing the number of qubits, the number of time points, and the target count.
The next lines each contain integers ( or ). The -th line represents the state sequence of the -th qubit over all time points.
Output Format
Output one line with one integer, indicating the total number of valid superpositions.
3 5 2
1 0 1 0 1
0 1 1 0 0
1 1 0 0 1
14
2 4 1
1 0 0 1
0 0 0 0
6
1 6 3
1 1 0 1 1 0
3
1 3 0
0 0 0
6
Hint
Sample Explanation 1
For the 1st qubit , the intervals that satisfy the condition are: , , , . There are intervals in total.
For the 2nd qubit , the intervals that satisfy the condition are: , , , , , . There are intervals in total.
For the 3rd qubit , the intervals that satisfy the condition are: , , , . There are intervals in total.
Therefore, the total count is .
Sample Explanation 2
For the 1st qubit , the intervals that contain exactly state equal to are: , , , , , . There are intervals in total.
For the 2nd qubit , there is no state equal to in any interval, so there are no intervals that contain exactly state equal to .
So the answer is .
Sample Explanation 3
The only qubit is .
The intervals that contain exactly states equal to are: , , . There are intervals in total.
Sample Explanation 4
The only qubit has state at all time points.
When , we need to count the cases where there are exactly states equal to in the interval, i.e., intervals where all values are .
When , there are intervals in total, and all of them satisfy the condition, so the answer is .
Constraints
For of the testdata, , .
For of the testdata, , .
For all testdata, , , . It is guaranteed that all state values in the input are either or .
Translated by ChatGPT 5