#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 SS of length nn initially has all bits set to zero. You are given nn operations. In each operation, you first flip one bit of SS, and then output the number of ordered pairs of binary strings (A,B)(A, B) that satisfy the following two conditions:

  • Both AA and BB are cyclically isomorphic to SS.
  • For every prefix of AA, its Hamming weight is not less than the Hamming weight of the prefix of BB 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, abc\texttt{abc} becomes bca\texttt{bca} after one left rotation, so they are cyclically isomorphic, but they are not cyclically isomorphic to cba\texttt{cba}.

The Hamming weight of a binary string is defined as the number of 1\texttt{1}s in it.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT (1≤T≤20001\le T\le 2000), indicating the number of test cases.

For each test case, the first line contains an integer nn (1≤n≤20001\le n\le 2000), denoting the length of the binary string.

The next line contains nn integers, where the ii-th integer denotes the index of the bit flipped in the ii-th operation. Indices start from 11.

It is guaranteed that ∑n≤2000\sum n\le 2000.

Output Format

Output TT lines. Each line contains nn 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, SS becomes 110\texttt{110}. At this time, there are 66 valid pairs (A,B)(A, B), which are:

  • $A=\texttt{110},B\in\{\texttt{110},\texttt{101},\texttt{011}\}$
  • A=101,B∈{101,011}A=\texttt{101},B\in\{\texttt{101},\texttt{011}\}
  • A=B=011A=B=\texttt{011}

Translated by ChatGPT 5