#P16120. [USTCPC 2026] Hamming Dominance
[USTCPC 2026] Hamming Dominance
Background
Please note that this problem has non-standard time and memory limits!
Due to performance differences among judge machines, the time limit has been adjusted to 2.5 s.
It is another sunny afternoon!
Kruskal-chan lies on the desk, staring at this problem in a daze.
“Wuwu... binary strings again... cyclic isomorphism again...”
A classmate leans over: “Kruskal-chan is still struggling with this problem?”
“I-I’m not struggling at all! I’m just thinking about life!”
Kruskal-chan pouts, and the pen in her hand spins in circles unconsciously.
But since you have already picked it up, let’s try to solve it!
Problem Description
A binary string of length initially has all bits set to zero. You are given operations. In each operation, you first flip one bit of , and then output the number of ordered pairs of binary strings that satisfy the following two conditions:
- Both and are cyclically isomorphic to .
- For every prefix of , its Hamming weight is not less than the Hamming weight of the prefix of of the same length.
Two strings are called cyclically isomorphic if and only if one of them can be transformed into the other by performing several left-rotation operations. Here, a “left rotation” means moving the first character of the string to the end. For example, becomes after one left rotation, so they are cyclically isomorphic, but they are not cyclically isomorphic to .
The Hamming weight of a binary string is defined as the number of s in it.
Input Format
This problem contains multiple test cases.
The first line contains an integer (), indicating the number of test cases.
For each test case, the first line contains an integer (), denoting the length of the binary string.
The next line contains integers, where the -th integer denotes the index of the bit flipped in the -th operation. Indices start from .
It is guaranteed that .
Output Format
Output lines. Each line contains integers, representing the number of valid ordered pairs after each flip.
2
5
1 2 3 4 1
3
2 1 1
15 13 13 15 13
6 6 6
Hint
In the second sample, after the second operation, becomes . At this time, there are valid pairs , which are:
- $A=\texttt{110},B\in\{\texttt{110},\texttt{101},\texttt{011}\}$
Translated by ChatGPT 5