You are given an array $$$a$$$ of $$$n$$$ non-negative integers and an integer $$$k$$$.
In one operation you can do:
Here $$$\&$$$ denotes the bitwise AND operation.
Find the minimum number of operations to make all elements to zero.
If it's impossible to make all elements to zero, output $$$-1$$$ instead.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10000$$$). The description of the test cases follows.
The first line of each testcase contains two integers $$$n,k$$$ ($$$1 \le n,k \le 10000$$$).
The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\ldots, a_n$$$ ($$$0 \le s_i \le 10000$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10000$$$.
For each test case, print a single integer — the minimum number of operations to make all elements to zero. If it's impossible to make all elements to zero, output $$$-1$$$ instead.
41 104 41 3 2 84 31 3 2 88 11 5 17 29 1000 11 45 22
0 1 2 -1
You're given three non-negative integers $$$n,x$$$ and $$$y$$$.
Determine if you can construct an array $$$a$$$ of size $$$n$$$ satisfying:
Here $$$|$$$ denotes the bitwise OR operation and $$$\&$$$ denotes the bitwise AND operation.
If you can construct such array $$$a$$$ output YES.Otherwise,output NO.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The only line of each testcase contains three integers $$$n,x,y$$$ ($$$1 \le n \le 2^{30}-1,0 \le x,y \le 2^{30}-1$$$).
For each testcase output in a new line — If you can construct such array $$$a$$$ output YES.Otherwise,output NO.
41 0 03 14 21000000000 14 23 6 5
YES YES NO NO
You are given a sequence of $$$n$$$ non-negative integers $$$a = [a_1, a_2, \dots, a_n]$$$.
You can perform the following operation any number of times:
Find the lexicographically smallest sequence that can be obtained by performing such operations.
Recall that MEX of a sequence is a minimum non-negative integer that does not belong to the sequence.
A sequence $$$a$$$ is lexicographically smaller than a sequence $$$b$$$ if and only if one of the following holds:
The first line of the input 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 $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, a_3, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$).
The sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output $$$n$$$ integers — the lexicographically smallest sequence that can be obtained by performing such operations.
470 3 0 1 2 4 040 1 2 351 0 1 0 131 3 5
0 1 0 1 2 3 0 0 1 2 3 0 0 1 0 1 0 0 0
In the first test case, you can perform such $$$2$$$ operations:
In the second test case, you can perform no operations.
In the third test case, you can perform a single operation:
This is the easy version of this problem.The only difference is that you can perform at most $$$3n$$$ operations.
You are given two binary strings $$$a$$$ and $$$b$$$ of the same length $$$n$$$.
You can perform the following operation:
Output any scheme to transform $$$a$$$ into $$$b$$$ by performing at most $$$3n$$$ operations.If there's no such scheme,output $$$-1$$$ instead.
The first line of the input 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 $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).
The second line contains the binary string $$$a$$$ of length $$$n$$$.
The third line contains the binary string $$$b$$$ of length $$$n$$$.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, if it is impossible to transform $$$a$$$ into $$$b$$$ by performing such operations, output $$$-1$$$.
Otherwise, output $$$2$$$ lines.
The first line should contain a single integer $$$m$$$ ($$$0 \le m \le 3 \cdot n$$$) — the number of operations.
The second line should contain $$$m$$$ integers ($$$1 \le i_1, i_2, \ldots, i_m \le n$$$) — indices defining the operations.
It is guaranteed that if there is a way to transform $$$a$$$ into $$$b$$$, then it can be done in at most $$$3 \cdot n$$$ operations.
420100200004101011016110000111111
-1 0 3 3 4 2 6 2 6 5 4 3 2
This is the easy version of this problem.The only difference is that you can perform at most $$$n$$$ operations.
You are given two binary strings $$$a$$$ and $$$b$$$ of the same length $$$n$$$.
You can perform the following operation:
Output any scheme to transform $$$a$$$ into $$$b$$$ by performing at most $$$n$$$ operations.If there's no such scheme,output $$$-1$$$ instead.
The first line of the input 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 $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).
The second line contains the binary string $$$a$$$ of length $$$n$$$.
The third line contains the binary string $$$b$$$ of length $$$n$$$.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, if it is impossible to transform $$$a$$$ into $$$b$$$ by performing such operations, output $$$-1$$$.
Otherwise, output $$$2$$$ lines.
The first line should contain a single integer $$$m$$$ ($$$0 \le m \le n$$$) — the number of operations.
The second line should contain $$$m$$$ integers ($$$1 \le i_1, i_2, \ldots, i_m \le n$$$) — indices defining the operations.
It is guaranteed that if there is a way to transform $$$a$$$ into $$$b$$$, then it can be done in at most $$$n$$$ operations.
420100200004101011016110000111111
-1 0 3 3 4 2 6 2 6 5 4 3 2
Raman is a curious kid who likes to play with arrays. One day, his friend Pradeep, a math nerd came to meet him. He gave Raman two arrays $$$a$$$ $$$(a_1,a_2,a_3,...,a_n)$$$ and $$$b$$$ $$$(b_1,b_2,b_3,...,b_n)$$$, both of size $$$n$$$, and asked this problem:
"Given $$$q$$$ queries of the form: $$$l$$$ $$$r$$$ , where $$$1\le l \le r \le n$$$ .
Find minimum possible positive integer $$$m$$$ such that $$$a_i \bmod m = b_i$$$ for all $$$l \le i \le r$$$. And, if no such $$$m$$$ exists, then print $$$-1$$$."
Raman finds the problem difficult to solve,and hence asks you for help. Please solve this problem for him.
The first line contains an integer $$$t (1 \le t \le 10^5)$$$ - the number of test cases.
The descriptions of the test cases follow.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ $$$(1 \le n,q \le 10^6)$$$ - the size of the array and the number of queries.
The second line contains $$$n$$$ space-separated non-negative integers $$$a_1, a_2, a_3, ..., a_n$$$ $$$(0 \le a_i \le 10^6)$$$ — the elements of array $$$a$$$.
The third line contains $$$n$$$ space-separated non-negative integers $$$b_1, b_2, b_3, ..., b_n$$$ $$$(0 \le b_i \le 10^6)$$$ — the elements of array $$$b$$$.
The next $$$q$$$ lines contain the queries: $$$l$$$ $$$r$$$ $$$(1 \le l \le r \le n)$$$.
It is guaranteed that the sum of $$$n$$$ and the sum of $$$q$$$ over all test cases do not exceed $$$10^6$$$.
For each query, output a single positive integer $$$m$$$, as required.
If no such $$$m$$$ exists, then print $$$-1$$$ for that query.
14 50 18 31 171 2 7 51 12 22 33 42 4
-1 4 8 12 -1
You are given a tree of $$$n$$$ nodes (the nodes are indexed from $$$1$$$ to $$$n$$$) that is rooted at node $$$1$$$.
Each node has a distinct value $$$a_i$$$ written on it. Let us define $$$Sub(u)$$$ to be the set of all nodes that are in the subtree of node $$$u$$$ (node $$$u$$$ is also included in its subtree).
You have to process $$$Q$$$ queries of $$$4$$$ different types. They are as follows:
It is guaranteed that, at any time, there are no two distinct nodes in the tree that have the same value.
Note: The $$$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$$$.
The first line contains two space separated integers denoting $$$n,q (2 \le n,q \le 2 \cdot 10^5)$$$.
The next line contains $$$n-1$$$ space separated integers $$$p_2, p_3, \dots, p_n(1 \le p_i \le n)$$$ where $$$p_i$$$ denotes an edge between node $$$p_i$$$ and $$$i$$$ where $$$p_i$$$ is the parent of $$$i$$$.
The next line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n(0 \le a_i \le 10^9)$$$.
The next $$$q$$$ lines contain the queries as described above.
It's guaranteed:
For each query of type $$$4$$$, print the answer in a new line.
5 51 2 3 35 4 3 2 11 5 7 04 52 33 2 04 2
2 1
