Let a partition of a multiset $$$B$$$ be a collection of multisets $$$s_1, s_2,\ldots, s_k$$$ such that each element appears the same number of times in $$$B$$$ and across all of $$$s_1,s_2,\ldots,s_k$$$.
For example, some partitions of $$$\{1,2,3,3\}$$$ include $$$\{1,3\}+\{2,3\}, \{1,2,3,3\}$$$, and $$$\{2\}+\{1,3\}+\{3\}$$$, but not $$$\{1,2\}+\{3\}$$$.
A partition is called valid if the $$$\operatorname{mex}$$$$$$^{\text{∗}}$$$ of all multisets in the partition is the same. The score of a valid partition is the $$$\operatorname{mex}$$$ of any multiset in the partition.
You are given a multiset $$$A$$$ of size $$$n$$$. Find the minimum score over all valid partitions of $$$A$$$.
$$$^{\text{∗}}$$$The minimum excluded (MEX) of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$).
The second line contains $$$n$$$ integers $$$A_1, A_2, \ldots, A_n$$$ denoting the elements of $$$A$$$ ($$$0 \leq A_i \leq 100$$$).
It is not guaranteed that the elements are given in non-decreasing order.
For each test case, output the minimum score over all valid partitions.
230 0 021 2
10
In the first test case, the minimum score of $$$1$$$ can be obtained by the partition $$$\{0\}+\{0\}+\{0\}$$$. The partition is valid because each multiset has a $$$\operatorname{mex}$$$ of $$$1$$$, which is consequently the score of the partition.
In the second test case, we can use $$$\{1,2\}$$$ as the only multiset in the partition, which has $$$\operatorname{mex} 0$$$.
Given an array $$$c$$$, let $$$f(c)$$$ be the number of distinct elements in $$$c$$$. For example, $$$f([1,2,2])=2$$$ because there are two distinct elements in $$$[1,2,2]$$$: $$$1$$$ and $$$2$$$. Also, define $$$c[i,j]$$$ as the subarray$$$^{\text{∗}}$$$ of $$$c$$$ bounded by positions $$$i$$$ and $$$j$$$ (that is, the array $$$[c_i,c_{i+1},\ldots,c_j]$$$).
There is an array $$$a$$$ of size $$$n$$$. An array $$$b$$$ of $$$n$$$ elements is constructed such that $$$b_i=f(a[1,i])+f(a[2,i])+\ldots+f(a[i,i])$$$. You are given the array $$$b$$$. Find any possible $$$a$$$ with elements $$$1 \leq a_i \leq n$$$. It is guaranteed that at least one possible $$$a$$$ exists.
$$$^{\text{∗}}$$$An array $$$x$$$ is a subarray of an array $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) – the number of elements in $$$a$$$ and $$$b$$$.
The second line of each test case contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$1 \leq b_i \leq 10^{18}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, print any possible $$$a$$$ on a new line. The array $$$a$$$ should satisfy $$$1\leq a_i\leq n$$$.
For every test case, it is guaranteed at least one $$$a$$$ that satisfies the conditions exists.
431 3 631 3 531 3 441 2 3 7
1 3 2 2 3 2 3 2 2 4 4 4 1
Let's verify our output for the second test case is correct:
Given a positive integer $$$x$$$, let $$$f(x)$$$ be the positive integer formed by reversing the binary representation of $$$x$$$ without leading zeroes. For example, if $$$x=12=1100_2$$$, then $$$f(x)=0011_2=3$$$.
You are given an integer $$$n$$$. Please determine if there exists a positive integer $$$x$$$ such that $$$x \oplus f(x) = n$$$$$$^{\text{∗}}$$$.
$$$^{\text{∗}}$$$Here, $$$\oplus$$$ denotes the bitwise XOR operation.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$0 \leq n \lt 2^{30}$$$).
For each test case, output YES if there exists a positive integer $$$x$$$ such that $$$x \oplus f(x) = n$$$, and NO otherwise.
You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" are also recognized as positive responses.
603681011
YESYESYESNOYESNO
In the first case, when $$$x=1$$$, $$$f(x)=1$$$, and $$$x \oplus f(x)=0$$$. Thus, the answer is YES.
In the second case, when $$$x=2$$$, $$$f(x)=1$$$, and $$$x \oplus f(x)=3$$$. Thus, the answer is YES.
In the fourth test case, we can show there is no $$$x$$$ that satisfies $$$x \oplus f(x)=8$$$, so the answer is NO.
This is an interactive problem.
There is a secret sequence $$$a_1, a_2, \ldots, a_{2n-1},a_{2n}$$$, which contains each integer from $$$1$$$ to $$$n$$$ exactly twice.
Your task is to guess the sequence by using queries of the following type:
We define the $$$\operatorname{MAD}$$$ (Maximum Appearing Duplicate) of an integer sequence as the largest integer that appears at least twice. Specifically, if there is no number that appears at least twice, the $$$\operatorname{MAD}$$$ value is $$$0$$$. Some examples are as follows:
Please identify the secret sequence using at most $$$3n$$$ queries.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 3000$$$). The description of the test cases follows.
The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 300$$$).
It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$10^5$$$.
After you read this line of input, the interaction begins with your first query.
To make a query, output a line (without quotes) in the following format:
Here, the indices $$$j_1 , j_2 , \ldots , j_k$$$ which you selected must be pairwise distinct.
Then, after each query, read a single integer — the answer to your query.
You can make at most $$$3n$$$ queries of this type.
If your program has found the sequence $$$a$$$, print the line (without quotes) in the following format:
Note that this does not count towards the query limit.
After this, proceed to the next test case, or exit if this is the last test case.
The interactor in this task is not adaptive. In other words, the sequence $$$a$$$ does not change during the interaction.
If you make more than $$$3n$$$ queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing each line, do not forget to output the end of line and flush the output buffer. Otherwise, you will receive the Idleness Limit Exceeded verdict. To flush, use:
Hacks
To make a hack, please use the following format:
The first line should contain the number of test cases $$$t$$$ ($$$1 \leq t \leq 3000$$$).
The first line of each test case should contain an integer $$$n$$$ ($$$2 \leq n \leq 300$$$).
The following line should contain $$$2n$$$ integers $$$a_1,a_2,\ldots,a_{2n}$$$ ($$$1 \leq a_i \leq n$$$). Each number from $$$1$$$ through $$$n$$$ must appear exactly twice.
The sum of $$$n^2$$$ over all test cases should not exceed $$$10^5$$$.
For example, the hack format corresponding to the example interaction is as follows.
2
2
2 2 1 1
2
1 2 1 2
2 2 2 0 1 2 0 1 1
? 2 2 1 ? 2 1 3 ? 3 1 3 4 ! 2 2 1 1 ? 2 1 2 ? 2 1 3 ? 3 1 3 4 ! 1 2 1 2
In the first test case, the hidden sequence is $$$a=[2,2,1,1]$$$.
For the query "? 2 2 1", the jury returns $$$2$$$ because $$$\operatorname{MAD}([a_2, a_1]) = \operatorname{MAD}([2, 2]) = 2$$$.
For the query "? 2 1 3", the jury returns $$$0$$$ because $$$\operatorname{MAD}([a_1, a_3]) = \operatorname{MAD}([2, 1]) = 0$$$.
For the query "? 3 1 3 4", the jury returns $$$1$$$ because $$$\operatorname{MAD}([a_1, a_3, a_4]) = \operatorname{MAD}([2 ,1, 1]) = 1$$$.
Note that the example interaction is only for understanding statements and does not guarantee finding a unique sequence $$$a$$$.
You are given a binary grid$$$^{\text{∗}}$$$ $$$G$$$ of dimensions $$$n \times m$$$.
Let us define a rectangle as a tuple $$$(u,d,l,r)$$$ that satisfies the following conditions:
Then, the area of a rectangle $$$(u,d,l,r)$$$ is defined as $$$(d-u+1) \cdot (r-l+1)$$$.
For example, consider the following binary grid given below.
$$$$$$\begin{matrix} 1 & 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 \end{matrix}$$$$$$
Here, you may see two rectangles $$$(1,2,1,3)$$$ and $$$(1,3,3,5)$$$$$$^{\text{†}}$$$, each of which has area $$$6$$$ and $$$9$$$, respectively.
For each cell $$$(i,j)$$$, find the minimum area of any rectangle $$$(u,d,l,r)$$$ such that $$$u \le i \le d$$$ and $$$l \le j \le r$$$.
$$$^{\text{∗}}$$$A binary grid is a grid where each cell contains $$$0$$$ or $$$1$$$. The cell on the $$$j$$$-th column of the $$$i$$$-th row is denoted as cell $$$(i,j)$$$.
$$$^{\text{†}}$$$Note that these are the only rectangles in the grid; for example, $$$(1,1,1,5)$$$ is not a rectangle as it does not satisfy $$$u \lt d$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m$$$, $$$n\cdot m \le 250\,000$$$).
Each of the $$$n$$$ following lines contains a string of length $$$m$$$ denoting the $$$i$$$-th row of $$$G$$$ ($$$G_{i,j} \in \{0,1\}$$$).
It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$250\,000$$$.
For each test case, output a grid of $$$n$$$ rows and $$$m$$$ columns. On the $$$j$$$-th column of the $$$i$$$-th row, you should output:
33 51010110100001014 60111010100011000101011105 51110010110111110110100111
6 6 6 9 96 6 6 9 90 0 9 9 90 10 8 8 10 100 10 8 8 10 1010 10 8 8 10 010 10 8 8 10 06 6 6 0 06 6 4 4 06 4 4 4 60 4 4 6 60 0 6 6 6
The first test case is explained in the statement.
For the third test case, there are six rectangles that cover at least one cell with minimum area:
A polynomial $$$f(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n$$$ is called a valid polynomial of degree $$$n$$$ if and only if $$$a_i$$$ is a non-negative integer for all $$$0 \le i \le n$$$ and $$$a_n$$$ is not $$$0$$$.
For a valid polynomial $$$f(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n$$$ of degree $$$n$$$, its twin polynomial $$$g(x)$$$ is defined as: $$$$$$ g(x) = \sum_{i=0}^n i \cdot x^{a_i} $$$$$$ For example, for $$$f(x) = 1 + 2x + 2x^3$$$, its twin polynomial is:
$$$$$$ g(x) = 0 \cdot x^{1} + 1 \cdot x^{2} + 2 \cdot x^{0} + 3 \cdot x^{2} = 0+x^2+2+3x^2= 2 + 4x^2 $$$$$$
A valid polynomial $$$f(x)$$$ of degree $$$n$$$ is called cool if and only if $$$f(x) = g(x)$$$. In other words, a valid polynomial of degree $$$n$$$ is cool if and only if its twin polynomial equals itself.
You are given an incomplete valid polynomial $$$f(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n$$$ of degree $$$n$$$. Some of $$$a_i$$$ have been determined, while others have not been determined. Additionally, it is guaranteed that $$$a_0$$$ and $$$a_n$$$ are not determined.
Please count the number of cool valid polynomials of degree $$$n$$$ that can be found by determining all undetermined $$$a_i$$$'s. Since the answer may be large, you need to output it modulo $$$1\,000\,000\,007$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
For each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 4 \cdot 10^5$$$).
The second line contains $$$n+1$$$ integers $$$a_0, a_1, \ldots, a_n$$$ ($$$-1 \leq a_i \leq 10^9$$$). Here, $$$a_i=-1$$$ means $$$a_i$$$ has not been determined, while $$$a_i \neq -1$$$ means $$$a_i$$$ has been determined as its value.
It is guaranteed that $$$a_0$$$ and $$$a_n$$$ are always $$$-1$$$ in the input.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4 \cdot 10^5$$$.
For each test case, output the number of cool valid polynomials of degree $$$n$$$ found by determining the undetermined $$$a_i$$$'s, modulo $$$1\,000\,000\,007$$$.
61-1 -12-1 2 -12-1 -1 -13-1 -1 3 -13-1 2 3 -15-1 -1 -1 1 0 -1
113203
In the first test case, only $$$f(x) = x$$$ satisfies the condition above.
In the second test case, only $$$f(x) = x^2 + 2x$$$ satisfies the condition above.
In the third test case, $$$f(x) = 2x^2 + x$$$, $$$f(x) = x^2 + 2x$$$, and $$$f(x) = 2x^2 + 1$$$ satisfy the condition above.
This is the easy version of the problem. The difference between the versions is that in this version, you are only asked to find $$$f(a)$$$. You can hack only if you solved all versions of this problem.
For some sequence $$$b$$$ of $$$k$$$ positive integers, the cost of the sequence is defined as follows$$$^{\text{∗}}$$$:
$$$$$$\mathtt{cost}(b)=\left\lceil{\frac{b_k}{\min(b_1,b_2,\ldots,b_k)}}\right\rceil$$$$$$
Assume that you partition a sequence $$$c$$$ into one or more sequences, so that the sequences become $$$c$$$ when concatenated. For example, when the sequence $$$c$$$ is $$$[3,1,4,1,5]$$$, a few valid ways to partition the sequence are $$$[[3,1],[4,1,5]]$$$, $$$[[3],[1,4,1],[5]]$$$, $$$[[3,1,4,1,5]]$$$. On the other hand, $$$[[3,1],[1,5]]$$$ and $$$[[3,4,1],[1,5]]$$$ are not valid ways to partition the sequence.
For a partition of a sequence $$$c$$$ of positive integers, the total cost of the partition is defined as the sum of the costs of each sequence in the partition. Then, let us define $$$f(c)$$$ as the minimum total cost to partition the sequence $$$c$$$.
Given a sequence $$$a$$$ of $$$n$$$ positive integers, you must compute the value of $$$f(a)$$$.
$$$^{\text{∗}}$$$Given a real value $$$x$$$, $$$\left\lceil{x}\right\rceil$$$ is defined as the smallest integer no less than $$$x$$$. For example, the value of $$$\left\lceil{3.14}\right\rceil$$$ is $$$4$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 4\cdot 10^5$$$).
The second line of each test case contains $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^{18}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4\cdot 10^5$$$.
For each test case, output the answer to the problem on a separate line.
453 1 4 1 5109 2 6 5 3 5 8 9 7 981 2 3 4 5 6 7 821 1000000000000000000
2452
For the first test case, the partition $$$[[3,1,4,1],[5]]$$$ gives a total cost of $$$1+1=2$$$.
For the second test case, the partition $$$[[9,2,6,5,3],[5,8,9,7,9]]$$$ gives a total cost of $$$2+2=4$$$.
For the third test case, the partition $$$[[1],[2,3,4],[5,6,7,8]]$$$ gives a total cost of $$$1+2+2=5$$$.
For the fourth test case, the partition $$$[[1],[1\,000\,000\,000\,000\,000\,000]]$$$ gives a total cost of $$$1+1=2$$$.
This is the hard version of the problem. The difference between the versions is that in this version, you are asked to find the sum of $$$f(b)$$$ over all contiguous subsequences $$$b$$$ of $$$a$$$. You can hack only if you solved all versions of this problem.
For some sequence $$$b$$$ of $$$k$$$ positive integers, the cost of the sequence is defined as follows$$$^{\text{∗}}$$$:
$$$$$$\mathtt{cost}(b)=\left\lceil{\frac{b_k}{\min(b_1,b_2,\ldots,b_k)}}\right\rceil$$$$$$
Assume that you partition a sequence $$$c$$$ into one or more sequences, so that the sequences become $$$c$$$ when concatenated. For example, when the sequence $$$c$$$ is $$$[3,1,4,1,5]$$$, a few valid ways to partition the sequence are $$$[[3,1],[4,1,5]]$$$, $$$[[3],[1,4,1],[5]]$$$, $$$[[3,1,4,1,5]]$$$. On the other hand, $$$[[3,1],[1,5]]$$$ and $$$[[3,4,1],[1,5]]$$$ are not valid ways to partition the sequence.
For a partition of a sequence $$$c$$$ of positive integers, the total cost of the partition is defined as the sum of the costs of each sequence in the partition. Then, let us define $$$f(c)$$$ as the minimum total cost to partition the sequence $$$c$$$.
Given a sequence $$$a$$$ of $$$n$$$ positive integers, you must compute the following:
$$$$$$\sum_{l=1}^{n} {\sum_{r=l}^{n} f([a_l,a_{l+1},\ldots,a_r])}$$$$$$
$$$^{\text{∗}}$$$Given a real value $$$x$$$, $$$\left\lceil{x}\right\rceil$$$ is defined as the smallest integer no less than $$$x$$$. For example, the value of $$$\left\lceil{3.14}\right\rceil$$$ is $$$4$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 4 \cdot 10^5$$$).
The second line of each test case contains $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^{18}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4 \cdot 10^5$$$.
For each test case, output the answer to the problem on a separate line.
453 1 4 1 5109 2 6 5 3 5 8 9 7 981 2 3 4 5 6 7 821 1000000000000000000
21124844
For the first test case, the following are all contiguous subsequences of $$$a$$$ and their corresponding values:
Therefore, the answer for the first test case is $$$1+1+2+1+2+1+2+1+2+1+1+2+1+2+1=21$$$.