You are given an integer array $$$a$$$ of length $$$n$$$, where each element is an integer between $$$1$$$ and $$$10^9$$$.
For a value $$$x$$$, let $$$\text{freq}(x)$$$ denote the number of times $$$x$$$ appears in the entire array $$$a$$$.
A contiguous subarray $$$a[l \ldots r]$$$ is called complete if the following condition holds:
In other words, if a value appears in the subarray, then all of its occurrences in the whole array must be contained within that subarray.
You are given multiple test cases. For each test case, determine the total number of complete subarrays of $$$a$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, print a single integer — the number of complete subarrays of $$$a$$$.
553 2 3 1 122 297 2 5 2 9 9 3 3 5105 10 6 1 9 2 7 2 4 397 1 6 5 1 2 9 6 3
4163710
In the first test case, subarrays $$$[2]$$$,$$$[1,1]$$$,$$$[3,2,3]$$$ and $$$[3,2,3,1,1]$$$ are complete while $$$[2,3]$$$ is not as it does not contain all occurrences of $$$3$$$.Thus,there are $$$4$$$ complete subarrays.
In the second test case, there is only one complete subarray, $$$[2,2]$$$.
This is a run-twice (communication) interactive problem.
There are two players: Player A and Player B. The jury (otherwise known as the interactor of this problem) will first interact with player A. After player A ends their interaction, the jury will interact with player B. Note that player A and player B may not directly pass information to each other; both players are only able to send information to or receive information from the jury.
There is a hidden $$$n \times n$$$ grid. It contains two special points: a pile of money at $$$M = (x_M, y_M)$$$ and a bomb at $$$B = (x_B, y_B)$$$. This setup is determined by the jury before the interaction, and is consistent across both players.
Player A receives the value of $$$n$$$ and the points $$$M$$$ and $$$B$$$ from the jury. Then, Player A must send an integer $$$k$$$ ($$$1 \le k \le x$$$) back to the jury, where $$$x$$$ is the limit on $$$k$$$.
Player B receives the value of $$$n$$$ and the value of $$$k$$$ (the same integer that Player A sent) from the jury. Their task is to determine the coordinates of point $$$M$$$. To do so, Player B can make at most $$$100$$$ queries of the form $$$(x, y, d)$$$ where $$$(x, y)$$$ is a point on the grid and $$$d$$$ is a direction (up/down/left/right).
Player A wants to ensure that player B can determine the coordinates of $$$M$$$. Let $$$x_{min}$$$ be the minimum value of the limit $$$x$$$ for which Player B can always do so safely, for any value $$$2 \le n \le 10^9$$$ and any valid coordinates for $$$M$$$ and $$$B$$$. Note that this value $$$x_{min}$$$ is a provable constant and is known to the jury — although you do not have to prove it (your solution only needs to respect the $$$x_{min}$$$ limit).
Your task is to act as both players and determine an optimal interaction strategy for both players so that player B determines the coordinates correctly, such that the integer $$$k$$$ follows the constraints $$$1 \le k \le x_{min}$$$.
FIRST RUN
Your code will run exactly twice on each test. On the first run, you will be Player A.
The first line of the input contains the string "first". The purpose of this is so your program recognises that this is its first run, and it should act as Player A.
The second line of the input contains exactly one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
The first line of each test case contains exactly one integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the dimension of the grid.
The second line of each test case contains two space-separated integers $$$x_M$$$ and $$$y_M$$$ ($$$1 \le x_M, y_M \le n$$$) — the coordinates of $$$M$$$.
The third line of each test case contains two space-separated integers $$$x_B$$$ and $$$y_B$$$ ($$$1 \le x_B, y_B \le n$$$) — the coordinates of $$$B$$$.
For each test case, print an integer $$$k$$$ ($$$1 \le k \le x_{min}$$$) on a new line. This is the integer that will be sent to you in the second run.
After this, proceed to the next test case, or terminate your program if it was the last test case.
SECOND RUN
On the second run, you are Player B.
The first line of the input contains the string "second". The purpose of this is so your program recognises that this is its second run, and it should act as Player B.
The second line of the input contains exactly one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Note that this number is equal to $$$t$$$ from the first run input.
The first line of each test case contains exactly one integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the dimension of the grid. Note that this number is equal to $$$n$$$ from the first run input.
The second line of each test case contains exactly one integer $$$k$$$ ($$$1 \le k \le x_{min}$$$) — the integer that was sent by Player A from the first run.
Note that the test cases in the second run may be shuffled. Please see the example test case for further illustration.
For each test case, recall you will first receive $$$n$$$ and $$$k$$$ in the input from the jury according to the input format above.
After receiving those inputs, you will be able to make at most $$$100$$$ queries of the following format: "? x y d" ($$$1 \le x, y \le n$$$ and $$$d \in \{U, D, L, R\}$$$).
After each query, the jury will respond with "Boom", "Yes", or "No" as described in the statement above. If you receive a "Boom" response in the same test case, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
Once you are ready to report the coordinates of $$$M$$$, you may do so in the format: "! x y" ($$$1 \le x, y \le n$$$), where $$$(x, y)$$$ is the coordinates you wish to report.
Then, you will either proceed to the next test case, or your program must terminate if you have processed every test case. Reporting the answer does not count towards the number of queries made.
The interactor is not adaptive. That is, the points $$$M$$$ and $$$B$$$ will not change during the interaction, and will always be the same positions as shown to you in the first run.
After printing each query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict.
first 3 # Test case 1 2 1 1 2 2 # Test case 2 4 4 4 4 2 # Test case 3 3 2 1 3 2
# Test case 1 1000000000 # Test case 2 1 # Test case 3 6
second 3 # Test case 1 3 6 No Yes Yes # Test case 2 2 1000000000 No # Test case 3 4 1 Yes No
# Test case 1 ? 2 1 R ? 1 3 L ? 1 1 D ! 2 1 # Test case 2 ? 1 1 R ! 1 1 # Test case 3 ? 3 3 D ? 3 3 L ! 4 4
For the first run:
For the second run: Note that the test cases are re-ordered between runs. However, note that the integer $$$k$$$ for each test case is the same as what is given in the first run.
As usual, as always, once again, Alice and Bob play a game with an array of integers. Both of them have a score of $$$0$$$ at the start of the game.
They start with an array $$$A$$$ of $$$n$$$ positive integers and play in turns. In each turn, the player must:
Equivalently, let $$$$$$x = t \cdot k^{p}$$$$$$ where $$$p \ge 1$$$ is the largest integer such that $$$k^{p}$$$ divides $$$x$$$, and $$$t \bmod k \neq 0$$$. Then, the original $$$x$$$ is removed from the array and the number $$$t$$$ is added back to the array.
The game ends when the array becomes empty. The winner is the player with the lower score at the end. If the scores are equal, the game is considered a tie.
Alice goes first. Given the initial array $$$A$$$, determine whether Alice wins the game or not, if both the players play optimally.
The first line of each test contains a single integer $$$t ~ (1 \leq t \leq 10^3 )$$$ — the number of test cases.
The first line of each test case contains a positive integer $$$n ~ (1 \leq n \leq 2 \cdot 10^5)$$$ — the number of elements in the array $$$A$$$.
The second line of each test case contains $$$n$$$ positive integers $$$a_1 , a_2 , ... , a_n ~ (1 \leq a_i \leq 10^9)$$$ — denoting the array elements.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$
For each test case, output a single line containing the word "YES" — if Alice wins the game and "NO" — otherwise.
418413 26 39 52370 30 70210 20
YESNOYESNO
For the first test case, the game proceeds as follows:
For the second test case, a possible game proceeds as follows:
You are given a tree with $$$n$$$ nodes and $$$n-1$$$ edges. Every edge $$$(u,v)$$$ has $$$w$$$ markable points. Each markable point can be marked at most once.
Each node $$$i$$$ has a permitted range $$$[l_i, r_i]$$$. Let $$$m_i$$$ denote the total number of marked points on edges incident to node $$$i$$$. For every node, the condition $$$l_i \le m_i \le r_i$$$ must hold.
You may choose any subset of nodes to supercharge. If node $$$i$$$ is supercharged:
If both nodes at the endpoints of an edge $$$(u,v)$$$ are supercharged, then the markable points on that edge reduces by 2 (1 because of each supercharged node).
You are allowed to mark at most $$$x$$$ points in total across the entire tree.
Your task is to compute the number of valid ways (respecting the permitted ranges of all nodes) to choose supercharged nodes and marked points, modulo $$$10^9 + 7$$$.
Two ways are considered identical if and only if:
The first line contains an integer $$$t$$$ $$$(1 \le t \le 250)$$$ — the number of test cases.
For each test case:
The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 250$$$, $$$0 \le x \le 25$$$).
The next $$$n-1$$$ lines describe the edges. Each line contains three integers $$$a$$$, $$$b$$$, and $$$w$$$ ($$$1 \le a,b \le n$$$, $$$a \ne b$$$, $$$2 \le w \le 2 \cdot 10^5$$$), describing an edge between nodes $$$a$$$ and $$$b$$$ of length $$$w$$$. It is guaranteed that the edges provided form a valid tree.
The next $$$n$$$ lines each contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le x$$$), describing the permitted range of node $$$i$$$.
Additional Constraints:
For each test case, output a single integer, the number of valid ways modulo $$$10^9 + 7$$$.
42 11 2 20 10 12 21 2 21 20 23 11 2 101 3 200 11 10 05 101 2 101 3 92 4 152 5 71 31 21 20 20 2
843813510619
If an edge has 1 markable point, let its name be a, and if the edge has 2 markable points, let their names be a and b.
For the first test case:
For the second test case:
For the third test case:
We will refrain from manually listing out the possibilities of the fourth test case.
There are $$$n$$$ bags labeled $$$1$$$ to $$$n$$$. Each bag contains a set of colored coins. A color is a lowercase letter from a to z. Within a bag, no color appears more than once.
The contents of bag $$$i$$$ are denoted by the set $$$S_i$$$.
You may apply the following operation any number of times:
The symmetric difference of two sets $$$A$$$ and $$$B$$$ is $$$$$$ A \Delta B = (A \setminus B) \cup (B \setminus A). $$$$$$
For each bag, its set of colors is given as a string of distinct lowercase letters (the order does not matter).
Your task is to determine whether it is possible to transform the initial contents of all bags into their target contents.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print YES if it is possible to reach the target contents of every bag, otherwise print NO.
53a b cab bc c4a bc d eabcde bcde de e3a b ca b d1abcab2a bb b
YESYESNONONO
For the first test case, performing the operation at $$$i = 1$$$ and then at $$$i = 2$$$ is sufficient to reach the target configuration.
For the second test case, the operation can be performed sequentially at $$$i = 3, 2, 1$$$ to obtain the target configuration.
For the third test case, the contents of the last bag in the initial and target configurations are different. Since bag $$$n$$$ is never changed by any operation, it is not possible to reach the target state.
For the fourth test case, the same reasoning applies: when $$$n = 1$$$, no operation can be performed, so the initial set must already match the target set. It does not, hence the target state cannot be reached.
For the fifth test case, the only possible move is at $$$i = 1$$$. After performing it, bag $$$1$$$ becomes $$$\{a\} \Delta \{b\} = \{a,b\}$$$, and further applications just alternate between $$$\{a\}$$$ and $$$\{a,b\}$$$. Therefore, the target state cannot be reached.
This is an interactive problem.
There is a hidden permutation$$$^†$$$ $$$p$$$ of size $$$n$$$.
You can make queries of another permutation $$$q$$$ of size $$$n$$$. The interactor will calculate and give you $$$\sum_{i=1}^{n} p_i \oplus q_i$$$.
Using at most $$$\frac{5n}{2}$$$ queries, find the hidden permutation $$$p$$$ and output it.
$$$^†$$$An array $$$a$$$ is a permutation of size $$$n$$$ if it contains each of the elements $$$0, 1, 2, ..., n-1$$$ exactly once.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows.
The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the size of the hidden permutation $$$p$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases is at most $$$1000$$$.
You can make queries in the following format — to query a permutation $$$q$$$, output one line of the form "? $$$q_1$$$ $$$q_2$$$ ... $$$q_n$$$" (where $$$q$$$ is a permutation of size $$$n$$$). After that, read a single integer — the value of $$$\Sigma_{i=1}^{n} p_i \oplus q_i$$$.
To report the hidden permutation as $$$q$$$, output "! $$$q_1$$$ $$$q_2$$$ ... $$$q_n$$$" (where $$$q$$$ is a permutation of size $$$n$$$). Then, the interaction continues with the next test case.
Reporting the answer does not count towards the number of queries made.
Note that you have to use the flush operation right after printing each line — otherwise you may get Idleness Limit Exceeded verdict. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.stdout.flush().
3 # Test case 1 4 0 # Test case 2 3 6 6 2 # Test case 3 6 16
# Test case 1 ? 2 0 1 3 ! 2 0 1 3 # Test case 2 ? 0 1 2 ? 1 2 0 ? 2 1 0 ! 2 0 1 # Test case 3 ? 0 1 2 3 4 5 ! 3 1 4 2 5 0
You do not have to handle comments (lines starting with #) in the input; they are only for presentation purposes and will not be present in the test cases.
The queries given in the sample input and output are for demonstrating the interaction, and may not logically lead to a correct output.
The participant's code correctly concludes that the hidden permutation is $$$[2, 0, 1, 3]$$$ and outputs it.
The participant's code correctly concludes that the hidden permutation is $$$[2, 0, 1]$$$ and outputs it.
The participant's code correctly concludes that the hidden permutation is $$$[3, 1, 4, 2, 5, 0]$$$ and outputs it.
ScepticallySam owns a speed packing service that uses robots to process packages.
Each robot is assigned a pair of indices $$$i \le j$$$ and performs the following operations on a line of packages:
A robot cannot move packages outside its assigned subarray.
Each line of packages is represented as an array of integers. For each line, ScepticallySam assigns robots to several non-overlapping subarrays, and all robots operate simultaneously.
After all robots finish, the entire line must be stamped and sorted in ascending order.
Given $$$t$$$ lines of packages, determine the maximum number of robots that can be assigned to each line while satisfying the above conditions.
Note: No robots were harmed in the making of this question.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) which represents the number of lines of packages.
The first line of the $$$i^{th}$$$ testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the number of packages in the line.
The second line of the $$$i^{th}$$$ testcase contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^9$$$) representing the weight of each package in the line.
It is guaranteed that the sum of $$$n$$$ (The total number of packages) over all the testcases does not exceed $$$2 \cdot 10^5$$$.
For each line of packages, output one integer, which is the maximum number of robots required to completely stamp and sort all the packages in the array.
341 2 3 444 3 2 151 2 3 5 4
414
In the first testcase, we can allocate 1 robot to each box since it's already sorted. Hence, 4 robots can be used, which is the maximum number of robots that can be used.
In the second testcase, we must allocate 1 robot to the entire sequence. It is not possible to achieve the goal in any other way.
In the third testcase, we can allocate 1 robot to each of the first three boxes and 1 robot to the last two boxes. So 4 robots in total.
You are given an array $$$a$$$ of length $$$n$$$ consisting of positive integers. You have to process $$$q$$$ queries of two types:
All indices are $$$1$$$-based.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \le t \le 10^{3})$$$. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ $$$(1 \le n \le 10^{5};\ 1 \le q \le 10^{5})$$$. The second line contains $$$n$$$ integers $$$a_1,\dots,a_n$$$ $$$(1 \le a_i \le 10^{6})$$$. Each of the next $$$q$$$ lines is one of:
For each query of type 1, print a single integer — the number of indices $$$j$$$ ($$$j \ne i$$$) such that $$$\gcd(a_i,a_j)=g$$$. Print each answer on a separate line.
24 212 8 9 181 1 121 4 25 101 1 2 3 61 1 11 5 22 2 12 3 11 5 31 4 62 1 61 1 62 1 61 2 1
01411014
In the first test case, for the first query we need to find elements in the array that satisfy $$$ \gcd(a_i, 12) = 12 \, \forall \, i \neq 1$$$. No such numbers exist in the array so the answer is 0. For the second query we need to find elements such that $$$ \gcd(a_i, 18) = 2 \, \forall \, i \neq 4$$$
In the second test case, for the first query all the numbers in the given array satisfy $$$ \gcd(a_i, 1) = 1$$$, so the answer is 4. For the second query, only $$$a_3 = 2$$$ satisfies $$$ \gcd (6, a_i) = 2$$$. After the third query, the array remains unchanged and after the fourth query it becomes $$$ [1,1,1,3,6] $$$. For the fifth query, only one element $$$ a_4 = 3 $$$ satisfies $$$ \gcd(6, a_j)=3 $$$
Your huge terrarium has a big glass panel. You have several stickers that you can paste onto the glass.
You have $$$n$$$ decorative stickers. For each sticker $$$i$$$ you are given:
You also have $$$m$$$ bottles of UV protecting cream. For each bottle $$$i$$$:
Example clarification: If you choose bottles 1 and 2, and decorative stickers 2, 4, and 6, then the following must hold: $$$au[1] + au[2] \lt = area[2] + area[4] + area[6]$$$.
Your scientists determine the following:
Find the maximum total beauty you can obtain. If it is impossible to keep the plants alive, output -1.
The first line contains the integer $$$t$$$ $$$(1 \le t \le 60)$$$, the number of testcases. For each test case we have:
The first line contains five integers $$$n, m, I, V, U$$$.
Then $$$n$$$ lines follow. The $$$i$$$-th of these lines contains four integers: $$$b[i], ir[i], vis[i], area[i]$$$.
Then $$$m$$$ lines follow. The $$$i$$$-th line contains two integers: $$$u[i]$$$, $$$au[i]$$$.
Constraints
Let $$$A_1 = \sum_{i=1}^n area[i]$$$ and $$$A_2 = \sum_{i=1}^n au[i]$$$
Additionally the following hold:
Print a single integer: the maximum achievable total beauty. If it is impossible to keep the plants alive, print -1.
23 3 50 3 53 2 1 24 3 2 35 4 10 47 18 110 1003 2 4 4 33 2 1 22 1 2 24 2 2 32 23 3
7 7
In the first example test case
The second example test case can also be reasoned out to show that 7 is the best we can do.
There are $$$n$$$ types of coins with you. There are $$$c_i$$$ many coins of the $$$i^{\text{th}}$$$ type, each having value $$$v_i$$$. You are interested in knowing the smallest fraction $$$p$$$ such that $$$p$$$ fraction of the coins hold at least $$$1-p$$$ fraction of the total value of all the coins.
More formally, let $$$C = \sum_{i=1}^{n}c_i$$$ and $$$V = \sum_{i=1}^{n}c_i \cdot v_i$$$. You have to find the smallest integer $$$x$$$ such that there exists a subset of $$$x$$$ coins which have at least $$$\left(1-\frac{x}{C}\right)\cdot V$$$ value.
You have to output the integer $$$x$$$.
The first line of each test contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of types of coins.
The second line of each test case contains $$$n$$$ space-separated integers $$$c_i$$$ ($$$1 \le c_i \le 1000$$$) — the number of coins of the $$$i^{\text{th}}$$$ type.
The third line of each test case contains $$$n$$$ space-separated integers $$$v_i$$$ ($$$1 \le v_i \le 1000$$$) — the value of one coin of the $$$i^{\text{th}}$$$ type.
There are no guarantees about the sum of $$$n$$$ over all test cases.
For each test case, output one line containing a single integer $$$x$$$ — the smallest integer as described above.
3110001437 37 37 371 2 4 2111000
500611
For test case 1, there is one type of coin, $$$1000$$$ in number and $$$1$$$ each in value. Here, $$$C = 1000$$$ and $$$V = 1000$$$. If we choose $$$x = 500$$$, we can select a subset of $$$500$$$ coins of type 1 each having value $$$1$$$ (total value is $$$500$$$), so that $$$500 \ge \left(1 - \frac{500}{1000}\right)\cdot 1000$$$ is true. It can be shown that $$$x \lt 500$$$ is not possible, so the minimum answer is $$$500$$$.
For test case 2, there are the following types of coins:
You are given an infinite 1-dimensional binary array of cells, which is indexed from $$$-\infty$$$ to $$$+\infty$$$. Initially, at time $$$t=0$$$, exactly $$$K$$$ distinct indices $$$P_1, P_2, \dots, P_K$$$ have the value $$$1$$$, and all other indices have the value $$$0$$$.
The array evolves over time steps $$$t=0, 1, 2, \dots$$$. The state of the array at time $$$t+1$$$ is derived from the state at time $$$t$$$ using the following rule for every index $$$i$$$:
$$$$$$ C_i^{(t+1)} = C_{i-1}^{(t)} \oplus C_{i+1}^{(t)} $$$$$$
where $$$\oplus$$$ denotes the bitwise XOR operation. (You might recognise this as elementary cellular automata on rule 90)
You must answer $$$Q$$$ queries. Each query consists of a target index $$$X$$$ and a time $$$T$$$. Determine the value of the cell at index $$$X$$$ at time $$$T$$$.
The first line contains two positive integers $$$K$$$ and $$$Q$$$ ($$$1 \le K, Q \le 1000$$$) — the number of initially active cells, and the number of queries respectively.
The second line contains $$$K$$$ distinct integers $$$P_1, P_2, \dots, P_K$$$ ($$$-10^{18} \le P_i \le 10^{18}$$$) — the indices of the cells that are initially $$$1$$$.
The next $$$Q$$$ lines each contains two integers $$$X$$$ and $$$T$$$ ($$$-10^{18} \le X \le 10^{18}$$$, $$$0 \le T \le 1000$$$) — the target index and the time step for the query.
For each query, output a single line containing '1' if the cell at index $$$X$$$ is active at time $$$T$$$, or '0' otherwise.
1 30-2 20 22 2
1 0 1
The example test case is illustrated below:
index: -3 -2 -1 0 1 2 3
at t=0: ...0 0 0 1 0 0 0...
at t=1: ...0 0 1 0 1 0 0...
at t=2: ...0 1 0 0 0 1 0...
Given an array $$$a$$$ of $$$n$$$ integers and a non-negative integer $$$k$$$, find the maximum integer $$$X$$$ such that there exists at least one valid contiguous subarray $$$a[l..r]$$$ satisfying the following conditions :
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$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$ and $$$k$$$ $$$(0 \le k \le 10^8)$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2 ... a_n$$$ $$$(1 \le a_i \le 10^8)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer $$$X$$$ that is the maximum integer satisfying the problem constraints.
53 1020 20 503 50100 5 1003 1000100 1 1003 10050 60 105 20100 10 100 10 100
20551005030
In the first test case, $$$a=[20,20,50]$$$, $$$k=10$$$. We choose the subarray $$$a[1…2]=[20,20]$$$ with target $$$X=20$$$.
Majority: Elements with value $$$\geq 20$$$ is $$$2$$$. Count is $$$2$$$, Length is $$$2$$$. Since Length $$$ \gt 1$$$ (more than half the subarray length), the condition holds.
Cost: All elements are already $$$\geq 20$$$, the cost is $$$0$$$ which is $$$\le 10$$$. It is impossible to achieve $$$X \gt 20$$$. For example, if $$$X = 21$$$, the only element $$$\geq 21$$$ is $$$50$$$. Any subarray including $$$50$$$ (e.g., $$$[20,50]$$$ or $$$[20,20,50]$$$) would have a majority count of only $$$1$$$, which is not strictly greater than half the length.
This is an interactive problem.
There is a hidden array $$$a$$$ of size $$$n$$$.
You can make queries of the following form:
Using at most $$$15 n$$$ queries, find the hidden array $$$a$$$ and output it.
$$$^†$$$The MEX of a set is the smallest non-negative integer that is not present in the set. For example, MEX($$$\{0, 1, 4, 5\}$$$) is $$$2$$$ and MEX($$$\{45\}$$$) is $$$0$$$.
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 only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 400$$$) — the size of the hidden array $$$a$$$ (although they will not be provided in the input, the elements of $$$a$$$ satisfy $$$0 \le a_i \le n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases is at most $$$400$$$.
You can make queries in the following format — to query subsets $$$P$$$ and $$$Q$$$, output one line of the form "? $$$x$$$ $$$y$$$" (where $$$x = |P|$$$ and $$$y = |Q|$$$). On the next line, output $$$x$$$ unique space-separated integers — the elements of $$$P$$$. On the next line, output $$$y$$$ unique space-separated integers — the elements of $$$Q$$$. After that, read a single integer — the value of MEX of $$$S$$$ (which is constructed as described above).
To report the hidden array as $$$b$$$, output "! $$$b_1$$$ $$$b_2$$$ ... $$$b_n$$$". Then, the interaction continues with the next test case.
Reporting the answer does not count towards the number of queries made.
Note that you have to use the flush operation right after printing each line — otherwise you may get Idleness Limit Exceeded verdict. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.stdout.flush().
3 # Test case 1 1 1 # Test case 2 6 3 0 # Test case 3 8 0
# Test case 1 ? 1 0 1 ! 0 # Test case 2 ? 3 1 2 6 4 0 ? 3 3 5 3 1 4 5 6 ! 3 1 4 2 5 0 # Test case 3 ? 8 1 1 2 3 4 5 6 7 8 8 ! 8 8 8 8 8 8 8 8
You do not have to handle comments (lines starting with #) in the input; they are only for presentation purposes and will not be present in the test cases.
The queries given in the sample input and output are for demonstrating the interaction, and may not logically lead to a correct output.
The participant's code makes one query, with $$$P = \{1\}$$$ and $$$Q = \{\}$$$. The interactor calculates $$$S = \{0\}$$$ and returns its MEX, $$$1$$$.
The participant's code correctly concludes that the hidden array is $$$[0]$$$ and outputs it.
The participant's code makes the first query query, with $$$P = \{2, 6, 4\}$$$ and $$$Q = \{0\}$$$. The interactor calculates $$$S = \{1, 0, 2\}$$$ and returns its MEX, $$$3$$$.
The participant's code makes the second query, with $$$P = \{5, 3, 1\}$$$ and $$$Q = \{4, 5, 6\}$$$. The interactor calculates $$$S = \{5, 4, 3, 6\}$$$ and returns its MEX, $$$0$$$.
The participant's code correctly concludes that the hidden array is $$$[3, 1, 4, 2, 5, 0]$$$ and outputs it.
You are given a binary string $$$s$$$ of length $$$n$$$. This binary string represents an integer (without trailing zeroes) $$$x$$$.
$$$m$$$ operations are then performed on this integer. In each operation, an integer $$$k$$$ is given, and the value of $$$x$$$ is updated to $$$\lfloor x \cdot 2^{k} \rfloor$$$. Equivalently, this operation can be understood as:
Output (without leading zeroes) the binary string corresponding to the final value of $$$x$$$ after all $$$m$$$ operations.
The first line of each test contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
The first line of each test case contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the binary string and the number of operations.
The second line of each test case contains a binary string $$$s$$$ (consisting only of the characters 0 and 1). It is guaranteed that $$$|s| = n$$$ and that the first character of $$$s$$$ is 1.
The third line of each test case contains $$$m$$$ space-separated integers $$$k_i$$$ ($$$-2 \cdot 10^5 \le k_i \le 2 \cdot 10^5$$$) — the value of $$$k$$$ for the $$$i^{\text{th}}$$$ operation. It is guaranteed that the sum of $$$k$$$ over all operations lies between $$$-2 \cdot 10^5$$$ and $$$2 \cdot 10^5$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases and the sum of $$$m$$$ over all test cases are both at most $$$2 \cdot 10^5$$$.
For each test case, output a single line containing a binary string corresponding to the final value of $$$x$$$. The binary string should not contain any leading zeroes — it should either be "0" or start with a 1.
21 21-1 1810 511111010102 -4 6 -8 10
01111100000000000
For the first test case, the binary string $$$s$$$ is "1" which corresponds to the integer $$$x = 1$$$.
For the second test case, the binary string $$$s$$$ is "1111101010" which corresponds to the integer $$$x = 2026$$$.