You are given an array $$$b_1, b_2, \ldots, b_n$$$.
An anonymous informant has told you that the array $$$b$$$ was obtained as follows: initially, there existed an array $$$a_1, a_2, \ldots, a_n$$$, after which the following two-component operation was performed $$$k$$$ times:
As a result of $$$k$$$ such operations, the array $$$b_1, b_2, \ldots, b_n$$$ was obtained. You want to check if the words of the anonymous informant can be true or if they are guaranteed to be false.
$$$^{\dagger}$$$A number $$$x$$$ is called a fixed point of the array $$$a_1, a_2, \ldots, a_n$$$ if $$$1 \leq x \leq n$$$ and $$$a_x = x$$$.
$$$^{\ddagger}$$$A cyclic left shift of the array $$$a_1, a_2, \ldots, a_n$$$ is the array $$$a_2, \ldots, a_n, a_1$$$.
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n, k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 10^9$$$) — the length of the array $$$b$$$ and the number of operations performed.
The second line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 10^9$$$) — the elements of the array $$$b$$$.
It is guaranteed that the sum of the values of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output "Yes" if the words of the anonymous informant can be true, and "No" if they are guaranteed to be false.
65 34 3 3 2 33 1007 2 15 56 1 1 1 11 100000000018 489 10 11 12 13 14 15 82 11 42
Yes Yes No Yes Yes No
In the first test case, the array $$$a$$$ could be equal to $$$[3, 2, 3, 4, 3]$$$. In the first operation, a fixed point $$$x = 2$$$ was chosen, and after $$$2$$$ left shifts, the array became $$$[3, 4, 3, 3, 2]$$$. In the second operation, a fixed point $$$x = 3$$$ was chosen, and after $$$3$$$ left shifts, the array became $$$[3, 2, 3, 4, 3]$$$. In the third operation, a fixed point $$$x = 3$$$ was chosen again, and after $$$3$$$ left shifts, the array became $$$[4, 3, 3, 2, 3]$$$, which is equal to the array $$$b$$$.
In the second test case, the array $$$a$$$ could be equal to $$$[7, 2, 1]$$$. After the operation with a fixed point $$$x = 2$$$, the array became $$$[1, 7, 2]$$$. Then, after the operation with a fixed point $$$x = 1$$$, the array returned to its initial state $$$[7, 2, 1]$$$. These same $$$2$$$ operations (with $$$x = 2$$$, and $$$x = 1$$$) were repeated $$$49$$$ times. So, after $$$100$$$ operations, the array returned to $$$[7, 2, 1]$$$.
In the third test case, it can be shown that there is no solution.
You are given an array $$$a$$$ consisting of $$$n$$$ integers, as well as an array $$$b$$$ consisting of $$$m$$$ integers.
Let $$$\text{LIS}(c)$$$ denote the length of the longest increasing subsequence of array $$$c$$$. For example, $$$\text{LIS}([2, \underline{1}, 1, \underline{3}])$$$ = $$$2$$$, $$$\text{LIS}([\underline{1}, \underline{7}, \underline{9}])$$$ = $$$3$$$, $$$\text{LIS}([3, \underline{1}, \underline{2}, \underline{4}])$$$ = $$$3$$$.
You need to insert the numbers $$$b_1, b_2, \ldots, b_m$$$ into the array $$$a$$$, at any positions, in any order. Let the resulting array be $$$c_1, c_2, \ldots, c_{n+m}$$$. You need to choose the positions for insertion in order to minimize $$$\text{LIS}(c)$$$.
Formally, you need to find an array $$$c_1, c_2, \ldots, c_{n+m}$$$ that simultaneously satisfies the following conditions:
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n, m$$$ $$$(1 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5)$$$ — the length of array $$$a$$$ and the length of array $$$b$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$ — the elements of the array $$$a$$$.
The third line of each test case contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ $$$(1 \leq b_i \leq 10^9)$$$ — the elements of the array $$$b$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$, and the sum of $$$m$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output $$$n + m$$$ numbers — the elements of the final array $$$c_1, c_2, \ldots, c_{n+m}$$$, obtained after the insertion, such that the value of $$$\text{LIS}(c)$$$ is minimized. If there are several answers, you can output any of them.
72 16 455 51 7 2 4 55 4 1 2 71 971 2 3 4 5 6 7 8 93 21 3 52 410 51 9 2 3 8 1 4 7 2 97 8 5 4 62 12 216 11 1 1 1 1 1777
6 5 4 1 1 7 7 2 2 4 4 5 5 9 8 7 7 6 5 4 3 2 1 1 3 5 2 4 1 9 2 3 8 8 1 4 4 7 7 2 9 6 5 2 2 1 777 1 1 1 1 1 1
In the first test case, $$$\text{LIS}(a) = \text{LIS}([6, 4]) = 1$$$. We can insert the number $$$5$$$ between $$$6$$$ and $$$4$$$, then $$$\text{LIS}(c) = \text{LIS}([6, 5, 4]) = 1$$$.
In the second test case, $$$\text{LIS}([\underline{1}, 7, \underline{2}, \underline{4}, \underline{5}])$$$ = $$$4$$$. After the insertion, $$$c = [1, 1, 7, 7, 2, 2, 4, 4, 5, 5]$$$. It is easy to see that $$$\text{LIS}(c) = 4$$$. It can be shown that it is impossible to achieve $$$\text{LIS}(c)$$$ less than $$$4$$$.
Let's define the anti-beauty of a multiset $$$\{b_1, b_2, \ldots, b_{len}\}$$$ as the number of occurrences of the number $$$len$$$ in the multiset.
You are given $$$m$$$ multisets, where the $$$i$$$-th multiset contains $$$n_i$$$ distinct elements, specifically: $$$c_{i, 1}$$$ copies of the number $$$a_{i,1}$$$, $$$c_{i, 2}$$$ copies of the number $$$a_{i,2}, \ldots, c_{i, n_i}$$$ copies of the number $$$a_{i, n_i}$$$. It is guaranteed that $$$a_{i, 1} \lt a_{i, 2} \lt \ldots \lt a_{i, n_i}$$$. You are also given numbers $$$l_1, l_2, \ldots, l_m$$$ and $$$r_1, r_2, \ldots, r_m$$$ such that $$$1 \le l_i \le r_i \le c_{i, 1} + \ldots + c_{i, n_i}$$$.
Let's create a multiset $$$X$$$, initially empty. Then, for each $$$i$$$ from $$$1$$$ to $$$m$$$, you must perform the following action exactly once:
You need to choose $$$v_1, \ldots, v_m$$$ and the added numbers in such a way that the resulting multiset $$$X$$$ has the minimum possible anti-beauty.
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$m$$$ ($$$1 \le m \le 10^5$$$) — the number of given multisets.
Then, for each $$$i$$$ from $$$1$$$ to $$$m$$$, a data block consisting of three lines is entered.
The first line of each block contains three integers $$$n_i, l_i, r_i$$$ ($$$1 \le n_i \le 10^5, 1 \le l_i \le r_i \le c_{i, 1} + \ldots + c_{i, n_i} \le 10^{17}$$$) — the number of distinct numbers in the $$$i$$$-th multiset and the limits on the number of elements to be added to $$$X$$$ from the $$$i$$$-th multiset.
The second line of the block contains $$$n_i$$$ integers $$$a_{i, 1}, \ldots, a_{i, n_i}$$$ ($$$1 \le a_{i, 1} \lt \ldots \lt a_{i, n_i} \le 10^{17}$$$) — the distinct elements of the $$$i$$$-th multiset.
The third line of the block contains $$$n_i$$$ integers $$$c_{i, 1}, \ldots, c_{i, n_i}$$$ ($$$1 \le c_{i, j} \le 10^{12}$$$) — the number of copies of the elements in the $$$i$$$-th multiset.
It is guaranteed that the sum of the values of $$$m$$$ for all test cases does not exceed $$$10^5$$$, and also the sum of $$$n_i$$$ for all blocks of all test cases does not exceed $$$10^5$$$.
For each test case, output the minimum possible anti-beauty of the multiset $$$X$$$ that you can achieve.
733 5 610 11 123 3 11 1 31242 4 412 131 517 1000 10061000 1001 1002 1003 1004 1005 1006147 145 143 143 143 143 14212 48 5048 5025 2521 1 1111 1 12111 1 11221 1 1112 1 11 21 124 8 1011 12 13 143 3 3 32 3 411 122 2
1 139 0 1 1 0 0
In the first test case, the multisets have the following form:
You can select the elements $$$\{10, 11, 11, 11, 12\}$$$ from the first multiset, $$$\{12\}$$$ from the second multiset, and $$$\{13, 13, 13, 13\}$$$ from the third multiset. Thus, $$$X = \{10, 11, 11, 11, 12, 12, 13, 13, 13, 13\}$$$. The size of $$$X$$$ is $$$10$$$, the number $$$10$$$ appears exactly $$$1$$$ time in $$$X$$$, so the anti-beauty of $$$X$$$ is $$$1$$$. It can be shown that it is not possible to achieve an anti-beauty less than $$$1$$$.
You have $$$n$$$ colored cubes, the $$$i$$$-th cube has color $$$a_i$$$.
You need to distribute all the cubes on shelves. There are a total of $$$m$$$ shelves, the $$$i$$$-th shelf can hold $$$s_i$$$ cubes. Also, $$$s_1 + s_2 + \ldots + s_m = n$$$.
Suppose on a shelf of size $$$k$$$ there are cubes of colors $$$c_1, c_2, \ldots, c_k$$$, in this order. Then we define the colorfulness of the shelf as the minimum distance between two different cubes of the same color on the shelf. If all the cubes on the shelf have different colors, then the colorfulness is considered to be equal to the size of the shelf, that is, the number $$$k$$$.
More formally, the colorfulness of $$$c_1, c_2, \ldots, c_k$$$ is defined as follows:
For each shelf, you are given the minimum required colorfulness, that is, you are given numbers $$$d_1, d_2, \ldots, d_m$$$, which mean that shelf $$$i$$$ must have a colorfulness $$$\geq d_i$$$ for all $$$i$$$.
Distribute the available cubes among the shelves to ensure the required colorfulness, or report that it is impossible.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n, m$$$ $$$(1 \leq m \leq n \leq 2 \cdot 10^5)$$$ — the number of cubes and the number of shelves to distribute them to.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq n)$$$ — the colors of the cubes.
The third line of each test case contains $$$m$$$ integers $$$s_1, s_2, \ldots, s_m$$$ $$$(1 \leq s_i \leq n)$$$ — the sizes of the shelves. It's guaranteed, that $$$s_1 + \ldots + s_m = n$$$.
The fourth line of each test case contains $$$m$$$ integers $$$d_1, d_2, \ldots, d_m$$$ $$$(1 \leq d_i \leq s_i)$$$ — the minimum required colorfulness of the shelves.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, if it is impossible to distribute the cubes on the shelves satisfying all the requirements, output a single number $$$-1$$$. Otherwise, output $$$m$$$ lines, where the $$$i$$$-th line should contain $$$s_i$$$ numbers representing the colors of the cubes on the $$$i$$$-th shelf, in the appropriate order.
610 31 1 1 1 2 2 2 3 3 46 2 24 1 18 27 7 7 7 8 8 8 84 42 25 15 4 3 2 1537 31 2 2 2 2 3 41 2 41 2 412 76 6 6 6 6 6 6 6 6 7 8 92 2 2 2 2 1 11 2 2 2 1 1 120 211 20 15 6 8 18 12 16 8 20 10 12 3 12 20 11 15 8 17 178 123 5
1 3 4 2 1 3 1 1 2 2 8 7 8 7 8 7 8 7 2 4 5 3 1 -1 6 6 7 6 8 6 9 6 6 6 6 6 12 17 20 15 8 20 16 11 15 20 17 12 10 8 3 18 12 11 8 6
You are given an undirected connected graph in which any two distinct simple cycles do not have common vertices. Since the graph can be very large, it is given to you in a compressed form: for each edge, you are also given a number $$$d$$$, which indicates that there are $$$d$$$ additional vertices on this edge.
You need to assign a weight to each vertex and each edge of the graph — an integer from $$$1$$$ to $$$3$$$.
An edge of the graph is called good if the bitwise XOR of the weights of its adjacent vertices is not equal to $$$0$$$ and not equal to the weight of that edge.
Similarly, a vertex of the graph is called good if the bitwise XOR of the weights of its adjacent edges is not equal to $$$0$$$ and not equal to the weight of that vertex.
You need to determine how many ways there are to assign weights to the vertices and edges of the graph so that all vertices and edges are good. Since the answer can be quite large, you need to calculate the remainder of the answer divided by $$$998\,244\,353$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ — the number of vertices and the number of edges in the graph ($$$2 \le n \le 5 \cdot 10^5$$$, $$$n - 1 \le m \le 10^6$$$).
Each of the next $$$m$$$ lines contains three integers $$$a_i, b_i$$$, and $$$d_i$$$ ($$$1 \le a_i, b_i \le n$$$, $$$a_i \ne b_i$$$, $$$0 \le d_i \le 10^9$$$), indicating that there is an edge in the graph connecting vertices $$$a_i$$$ and $$$b_i$$$. Additionally, on this edge, there are $$$d_i$$$ additional vertices. It is guaranteed that the given graph is connected, there are no multiple edges, loops, and any two distinct simple cycles of the graph do not have common vertices.
Output a single integer — the answer to the problem modulo $$$998\,244\,353$$$.
3 3 1 2 0 2 3 0 3 1 0
12
6 7 1 2 0 2 3 0 3 1 0 4 5 0 5 6 0 6 4 0 4 3 0
0
2 1 2 1 777
0
3 3 1 2 0 2 3 110850709 3 1 1000000000
179179178
In the first test, the graph is a simple cycle of $$$3$$$ vertices. It can be shown, that there are exactly $$$12$$$ ways to assign weights, to make all vertexes and edges good.
In the second test, the graph has the form of two simple cycles of $$$3$$$ vertices connected by an edge. It can be shown that for such a graph there are no ways to arrange weights so that all vertices and edges are good.