NIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to $$$\operatorname{or} z$$$. Can you solve this problem too?
You are given a 1-indexed array of $$$n$$$ integers, $$$a$$$, and an integer $$$z$$$. You can do the following operation any number (possibly zero) of times:
Here $$$\operatorname{or}$$$ and $$$\operatorname{and}$$$ denote the bitwise operations OR and AND respectively.
Find the maximum possible value of the maximum value in $$$a$$$ after any number (possibly zero) of operations.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$z$$$ ($$$1\le n\le 2000$$$, $$$0\le z \lt 2^{30}$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1$$$,$$$a_2$$$,$$$\ldots$$$,$$$a_n$$$ ($$$0\le a_i \lt 2^{30}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.
For each test case, print one integer — the answer to the problem.
52 33 45 50 2 4 6 81 9105 77 15 30 29 273 3954874310293834 10284344 13635445
7 13 11 31 48234367
In the first test case of the sample, one optimal sequence of operations is:
After these operations, the sequence $$$a$$$ becomes $$$[3,7]$$$, and the maximum value in it is $$$7$$$. We can prove that the maximum value in $$$a$$$ can never exceed $$$7$$$, so the answer is $$$7$$$.
In the fourth test case of the sample, one optimal sequence of operations is:
For a collection of integers $$$S$$$, define $$$\operatorname{mex}(S)$$$ as the smallest non-negative integer that does not appear in $$$S$$$.
NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by snapping his fingers several times.
The universe can be represented as a 1-indexed array $$$a$$$ of length $$$n$$$. When NIT snaps his fingers, he does the following operation on the array:
We say the universe is destroyed if and only if for all $$$1\le i\le n$$$, $$$a_i=0$$$ holds.
Find the minimum number of times NIT needs to snap his fingers to destroy the universe. That is, find the minimum number of operations NIT needs to perform to make all elements in the array equal to $$$0$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$0\le a_i\le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print one integer — the answer to the problem.
440 0 0 050 1 2 3 470 2 3 0 1 2 011000000000
0 1 2 1
In the first test case, we do $$$0$$$ operations and all elements in the array are already equal to $$$0$$$.
In the second test case, one optimal way is doing the operation with $$$l=2$$$, $$$r=5$$$.
In the third test case, one optimal way is doing the operation twice, respectively with $$$l=4$$$, $$$r=4$$$ and $$$l=2$$$, $$$r=6$$$.
In the fourth test case, one optimal way is doing the operation with $$$l=1$$$, $$$r=1$$$.
Fishingprince is playing with an array $$$[a_1,a_2,\dots,a_n]$$$. He also has a magic number $$$m$$$.
He can do the following two operations on it:
Note that the array length might change during the process. The value of $$$n$$$ above is defined as the current length of the array (might differ from the $$$n$$$ in the input).
Fishingprince has another array $$$[b_1,b_2,\dots,b_k]$$$. Please determine if he can turn $$$a$$$ into $$$b$$$ using any number (possibly zero) of operations.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 5\cdot 10^4$$$, $$$2\le m\le 10^9$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$).
The third line of each test case contains one integer $$$k$$$ ($$$1\le k\le 5\cdot 10^4$$$).
The fourth line of each test case contains $$$k$$$ integers $$$b_1,b_2,\ldots,b_k$$$ ($$$1\le b_i\le 10^9$$$).
It is guaranteed that the sum of $$$n+k$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each testcase, print Yes if it is possible to turn $$$a$$$ into $$$b$$$, and No otherwise. You can print each letter in any case (upper or lower).
55 21 2 2 4 241 4 4 26 21 2 2 8 2 221 168 33 3 3 3 3 3 3 346 6 6 68 33 9 6 3 12 12 36 12169 3 2 2 2 3 4 12 4 12 4 12 4 12 4 48 33 9 6 3 12 12 36 12712 2 4 3 4 12 56
Yes Yes No Yes No
In the first test case of the sample, we can do the second operation with $$$i=2$$$: $$$[1,\color{red}{2,2},4,2]\to [1,\color{red}{4},4,2]$$$.
In the second testcase of the sample, we can:
A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
You are given a permutation of $$$1,2,\dots,n$$$, $$$[a_1,a_2,\dots,a_n]$$$. For integers $$$i$$$, $$$j$$$ such that $$$1\le i \lt j\le n$$$, define $$$\operatorname{mn}(i,j)$$$ as $$$\min\limits_{k=i}^j a_k$$$, and define $$$\operatorname{mx}(i,j)$$$ as $$$\max\limits_{k=i}^j a_k$$$.
Let us build an undirected graph of $$$n$$$ vertices, numbered $$$1$$$ to $$$n$$$. For every pair of integers $$$1\le i \lt j\le n$$$, if $$$\operatorname{mn}(i,j)=a_i$$$ and $$$\operatorname{mx}(i,j)=a_j$$$ both holds, or $$$\operatorname{mn}(i,j)=a_j$$$ and $$$\operatorname{mx}(i,j)=a_i$$$ both holds, add an undirected edge of length $$$1$$$ between vertices $$$i$$$ and $$$j$$$.
In this graph, find the length of the shortest path from vertex $$$1$$$ to vertex $$$n$$$. We can prove that $$$1$$$ and $$$n$$$ will always be connected via some path, so a shortest path always exists.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5\cdot 10^4$$$). Description of the test cases follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 2.5\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1\le a_i\le n$$$). It's guaranteed that $$$a$$$ is a permutation of $$$1$$$, $$$2$$$, $$$\dots$$$, $$$n$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
For each test case, print a single line containing one integer — the length of the shortest path from $$$1$$$ to $$$n$$$.
51121 251 4 2 3 552 1 5 3 4107 4 8 1 6 10 3 5 2 9
0 1 1 4 6
The following are illustrations of constructed graphs in example test cases.
the constructed graph in test case 1
the constructed graph in test case 2
the constructed graph in test case 3
the constructed graph in test case 4
the constructed graph in test case 5
We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.
There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are numbered $$$0$$$ to infinity from top to bottom, columns are numbered from $$$0$$$ to infinity from left to right.
There is also a non-increasing infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$. You are given $$$a_0$$$, $$$a_1$$$, $$$\ldots$$$, $$$a_n$$$; for all $$$i \gt n$$$, $$$a_i=0$$$. For every pair of $$$x$$$, $$$y$$$, the cell with coordinates $$$(x,y)$$$ (which is located at the intersection of $$$x$$$-th row and $$$y$$$-th column) is white if $$$y \lt a_x$$$ and black otherwise.
Initially there is one doll named Jina on $$$(0,0)$$$. You can do the following operation.
Note that multiple dolls can be present at a cell at the same time; in one operation, you remove only one. Your goal is to make all white cells contain $$$0$$$ dolls.
What's the minimum number of operations needed to achieve the goal? Print the answer modulo $$$10^9+7$$$.
The first line of input contains one integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$).
The second line of input contains $$$n+1$$$ integers $$$a_0,a_1,\ldots,a_n$$$ ($$$0\le a_i\le 2\cdot 10^5$$$).
It is guaranteed that the sequence $$$a$$$ is non-increasing.
Print one integer — the answer to the problem, modulo $$$10^9+7$$$.
2 2 2 0
5
10 12 11 8 8 6 6 6 5 3 2 1
2596
Consider the first example. In the given grid, cells $$$(0,0),(0,1),(1,0),(1,1)$$$ are white, and all other cells are black. Let us use triples to describe the grid: triple $$$(x,y,z)$$$ means that there are $$$z$$$ dolls placed on cell $$$(x,y)$$$. Initially the state of the grid is $$$(0,0,1)$$$.
One of the optimal sequence of operations is as follows:
Now all white cells contain $$$0$$$ dolls, so we have achieved the goal with $$$5$$$ operations.
Fishingprince loves trees. A tree is a connected undirected graph without cycles.
Fishingprince has a tree of $$$n$$$ vertices. The vertices are numbered $$$1$$$ through $$$n$$$. Let $$$d(x,y)$$$ denote the shortest distance on the tree from vertex $$$x$$$ to vertex $$$y$$$, assuming that the length of each edge is $$$1$$$.
However, the tree was lost in an accident. Fortunately, Fishingprince still remembers some information about the tree. More specifically, for every triple of integers $$$x,y,z$$$ ($$$1\le x \lt y\le n$$$, $$$1\le z\le n$$$) he remembers whether $$$d(x,z)=d(y,z)$$$ or not.
Help him recover the structure of the tree, or report that no tree satisfying the constraints exists.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). Description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$2\le n\le 100$$$) — the number of vertices in the tree.
Then $$$n-1$$$ lines follow. The $$$i$$$-th line of these $$$n-1$$$ lines contains $$$n-i$$$ strings of length $$$n$$$ consisting of 0 and 1. If the $$$k$$$-th character in the $$$j$$$-th string of the $$$i$$$-th line is 0, it means that $$$d(i,k)\ne d(i+j,k)$$$; if the $$$k$$$-th character in the $$$j$$$-th string of the $$$i$$$-th line is 1, it means that $$$d(i,k)=d(i+j,k)$$$.
It is guaranteed that in one input file,
For each test case:
When printing Yes and No, you can print each letter in any case (upper or lower).
52002103001 0000003001 010000500000 01001 00000 0110000000 10000 0000000000 1101000000
Yes 1 2 No Yes 1 3 2 3 No Yes 1 2 1 4 2 3 2 5
Suppose you are given a 1-indexed sequence $$$a$$$ of non-negative integers, whose length is $$$n$$$, and two integers $$$x$$$, $$$y$$$. In consecutive $$$t$$$ seconds ($$$t$$$ can be any positive real number), you can do one of the following operations:
Define the minimum amount of time (it might be a real number) required to make all elements in the sequence less than or equal to $$$0$$$ as $$$f(a)$$$.
For example, when $$$x=1$$$, $$$y=2$$$, it takes $$$3$$$ seconds to deal with the array $$$[3,1,1,3]$$$. We can:
We can prove that it's not possible to make all elements less than or equal to $$$0$$$ in less than $$$3$$$ seconds, so $$$f([3,1,1,3])=3$$$.
Now you are given a 1-indexed sequence $$$b$$$ of positive integers, whose length is $$$n$$$. You are also given positive integers $$$x$$$, $$$y$$$. Process $$$q$$$ queries of the following two types:
The first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$2\le n\le 2\cdot 10^5$$$, $$$1\le q\le 2\cdot 10^5$$$).
The second line of input contains two integers $$$x$$$ and $$$y$$$ ($$$1\le x,y\le 10^6$$$).
The third line of input contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$1\le b_i\le 10^6$$$).
This is followed by $$$q$$$ lines. Each of these $$$q$$$ lines contains three integers. The first integer $$$op$$$ is either $$$1$$$ or $$$2$$$.
For each query of type $$$2$$$, print one real number — the answer to the query. Your answer is considered correct if its absolute error or relative error does not exceed $$$10^{-9}$$$.
4 3 1 2 3 1 1 4 2 1 4 1 1 1 2 1 3
3.500000000000000 1.000000000000000
Let's analyse the sample.
In the first query, we are asked to compute $$$f([3,1,1,4])$$$. The answer is $$$3.5$$$. One optimal sequence of operations is:
In the third query, we are asked to compute $$$f([1,1,1])$$$. The answer is $$$1$$$. One optimal sequence of operations is:
You are given a positive integer $$$k$$$. For a multiset of integers $$$S$$$, define $$$f(S)$$$ as the following.
More formally, let $$$|S|$$$ denote the number of elements in $$$S$$$. Then,
You are given a multiset of integers, $$$A$$$. Compute $$$\sum\limits_{B\subseteq A} f(B)$$$ modulo $$$10^9+7$$$.
Note that in this problem, we distinguish the elements by indices instead of values. That is, a multiset consisting of $$$n$$$ elements always has $$$2^n$$$ distinct subsets regardless of whether some of its elements are equal.
The first line of input contains two integers $$$n$$$ and $$$k$$$, where $$$n$$$ is the number of elements in $$$A$$$ ($$$1\le k\le n\le 600$$$).
The second line of input contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$, describing the elements in $$$A$$$ ($$$-10^9\le a_i\le 10^9$$$).
Output $$$\sum\limits_{B\subseteq A} f(B)$$$ modulo $$$10^9+7$$$.
3 2 -1 2 4
10
3 1 1 1 1
7
10 4 -24 -41 9 -154 -56 14 18 53 -7 120
225905161
15 5 0 0 2 -2 2 -2 3 -3 -3 4 5 -4 -4 4 5
18119684
Consider the first sample. From the definitions we know that
So we should print $$$(0+0+0+0-2-4+8+8)\bmod (10^9+7)=10$$$.
In the second example, note that although the multiset consists of three same values, it still has $$$8$$$ distinct subsets: $$$\varnothing,\{1\},\{1\},\{1\},\{1,1\},\{1,1\},\{1,1\},\{1,1,1\}$$$.