You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$. In one operation, you do the following:
Can you sort the array in non-decreasing order by performing some number (possibly zero) of operations?
An array is considered non-decreasing if $$$a_i \leq a_{i + 1}$$$ for all integers $$$i$$$ such that $$$1 \leq i \leq n - 1$$$.
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 a single integer $$$n$$$ ($$$1 \leq n \leq 20$$$) — the length of array $$$a$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the integers in array $$$a$$$ ($$$0 \leq a_i \leq 1000$$$).
For each test case, output "YES" if the array can be sorted, and "NO" otherwise.
851 2 3 4 556 5 3 4 496 5 5 7 5 6 6 8 744 3 2 162 2 4 5 3 281 3 17 19 27 57 179 1353 17 57 179 92101 2 3 4 0 6 7 8 9 10
YES YES YES NO NO NO YES YES
In the first test case, the array is already sorted in non-decreasing order, so we don't have to perform any operations.
In the second test case, we can choose $$$m = 1$$$ twice to get the array $$$[4, 3, 3, 4, 4]$$$. Then, we can choose $$$m = 0$$$ once and get the sorted in non-decreasing order array $$$[3, 3, 3, 4, 4]$$$.
In the third test case, we can choose $$$m = 0$$$ once and get the array $$$[5, 5, 5, 7, 5, 6, 6, 8, 7]$$$. Then, we can choose $$$m = 2$$$ twice and get the array $$$[3, 3, 3, 5, 5, 6, 6, 8, 7]$$$. After that, we can choose $$$m = 3$$$ once and get the sorted in non-decreasing order array $$$[2, 2, 2, 4, 4, 5, 5, 7, 7]$$$.
For the fourth and fifth test case, it can be shown that the array could not be sorted using these operations.
You are given an array $$$a$$$ of length $$$n$$$, consisting of positive integers, and an array $$$x$$$ of length $$$q$$$, also consisting of positive integers.
There are $$$q$$$ modification. On the $$$i$$$-th modification ($$$1 \leq i \leq q$$$), for each $$$j$$$ ($$$1 \leq j \leq n$$$), such that $$$a_j$$$ is divisible by $$$2^{x_i}$$$, you add $$$2^{x_i-1}$$$ to $$$a_j$$$. Note that $$$x_i$$$ ($$$1 \leq x_i \leq 30$$$) is a positive integer not exceeding 30.
After all modification queries, you need to output the final array.
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$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^5$$$) —the length of the array $$$a$$$ and the number of queries respectively.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$ — the elements of the array $$$a$$$ ($$$1 \leq a_i \leq 10^9$$$).
The third line of each test case contains $$$q$$$ integers $$$x_1, x_2, x_3, \ldots, x_q$$$ — the elements of the array $$$x$$$ ($$$1 \leq x_i \leq 30$$$), which are the modification queries.
It is guaranteed that the sum of $$$n$$$ and the sum of $$$q$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output the array after all of the modification queries.
45 31 2 3 4 42 3 47 37 8 12 36 48 6 310 4 25 42 2 2 2 21 1 1 15 51 2 4 8 165 2 3 4 1
1 2 3 6 6 7 10 14 38 58 6 3 3 3 3 3 3 1 3 7 11 19
In the first test case, the first query will add $$$2$$$ to the integers in positions $$$4$$$ and $$$5$$$. After this addition, the array would be $$$[1, 2, 3, 6, 6]$$$. Other operations will not modify the array.
In the second test case, the first modification query does not change the array. The second modification query will add $$$8$$$ to the integer in position $$$5$$$, so that the array would look like this: $$$[7, 8, 12, 36, 56, 6, 3]$$$. The third modification query will add $$$2$$$ to the integers in positions $$$2, 3$$$, $$$4$$$ and $$$5$$$. The array would then look like this: $$$[7, 10, 14, 38, 58, 6, 3]$$$.
A boy called Smilo is playing a new game! In the game, there are $$$n$$$ hordes of monsters, and the $$$i$$$-th horde contains $$$a_i$$$ monsters. The goal of the game is to destroy all the monsters. To do this, you have two types of attacks and a combo counter $$$x$$$, initially set to $$$0$$$:
Your task is to destroy all of the monsters, meaning that there should be no monsters left in any of the hordes. Smilo wants to win as quickly as possible, so he wants to the minimum number of attacks required to win the game.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The descriptions of the test cases follow.
The first line of each input data set contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of hordes of monsters.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the number of monsters in each horde.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot {10^5}$$$.
For each test case, out put the minimum number of attacks required to kill all monsters.
441 3 1 141 2 1 163 2 1 5 2 421 6
4 4 11 5
In the first test case, we can use an attack of the first type on the $$$1$$$-st, $$$3$$$-rd and $$$4$$$-th hordes, and then use an attack of the second type to finish off the $$$2$$$-nd horde. We need $$$4$$$ attacks in total.
In the second test case, we can use an attack of the first type on the $$$1$$$-st and $$$3$$$-rd hordes, then use an attack of the second type to finish off the $$$2$$$-nd horde, and then use an attack of the first type on the $$$4$$$-th horde. We need $$$4$$$ attacks in total.
In the fourth test case, we can use an attack of the first type once on the $$$1$$$-st horde, twice on the $$$2$$$-nd horde, and then use an attack of the second type on the $$$2$$$-nd horde, and finally use an attack of the first type to finish off the $$$2$$$-nd horde. We need $$$5$$$ attacks in total.
Let $$$f$$$($$$x$$$) be the floor of the binary logarithm of $$$x$$$. In other words, $$$f$$$($$$x$$$) is largest non-negative integer $$$y$$$, such that $$$2^y$$$ does not exceed $$$x$$$.
Let $$$g$$$($$$x$$$) be the floor of the logarithm of $$$x$$$ with base $$$f$$$($$$x$$$). In other words, $$$g$$$($$$x$$$) is the largest non-negative integer $$$z$$$, such that $$${f(x)}^{z}$$$ does not exceed $$$x$$$.
You are given $$$q$$$ queries. The $$$i$$$-th query consists of two integers $$$l_i$$$ and $$$r_i$$$. The answer to the query is the sum of $$$g$$$($$$k$$$) across all integers $$$k$$$, such that $$$l_i \leq k \leq r_i$$$. Since the answers might be large, print them modulo $$${10^9 + 7}$$$.
The first line contains a single integer $$$q$$$ — the number of queries ($$$1 \leq q \leq 10^5$$$).
The next $$$q$$$ lines each contain two integers $$$l_i$$$ and $$$r_i$$$ — the bounds of the $$$i$$$-th query ($$$4 \leq l_i \leq r_i \leq 10^{18}$$$).
For each query, output the answer to the query modulo $$$10^9 + 7$$$.
12 4 6 4 7 4 8 4 100000 179 1000000000000000000 57 179 4 201018959 7 201018960 729 50624 728 50624 728 50625 729 50625
6 8 9 348641 41949982 246 1 0 149688 149690 149694 149692
The table below contains the values of the functions $$$f$$$($$$x$$$) and $$$g$$$($$$x$$$) for all $$$x$$$ such that $$$1 \leq x \leq 8$$$.
| $$$x$$$ | $$$1$$$ | $$$2$$$ | $$$3$$$ | $$$4$$$ | $$$5$$$ | $$$6$$$ | $$$7$$$ | $$$8$$$ |
| $$$f$$$ | $$$0$$$ | $$$1$$$ | $$$1$$$ | $$$2$$$ | $$$2$$$ | $$$2$$$ | $$$2$$$ | $$$3$$$ |
| $$$g$$$ | $$$-$$$ | $$$-$$$ | $$$-$$$ | $$$2$$$ | $$$2$$$ | $$$2$$$ | $$$2$$$ | $$$1$$$ |
The boy Smilo is learning algorithms with a teacher named Brukhovich.
Over the course of the year, Brukhovich will administer $$$n$$$ exams. For each exam, its difficulty $$$a_i$$$ is known, which is a non-negative integer.
Smilo doesn't like when the greatest common divisor of the difficulties of two consecutive exams is equal to $$$1$$$. Therefore, he considers the sadness of the academic year to be the number of such pairs of exams. More formally, the sadness is the number of indices $$$i$$$ ($$$1 \leq i \leq n - 1$$$) such that $$$gcd(a_i, a_{i+1}) = 1$$$, where $$$gcd(x, y)$$$ is the greatest common divisor of integers $$$x$$$ and $$$y$$$.
Brukhovich wants to minimize the sadness of the year of Smilo. To do this, he can set the difficulty of any exam to $$$0$$$. However, Brukhovich doesn't want to make his students' lives too easy. Therefore, he will perform this action no more than $$$k$$$ times.
Help Smilo determine the minimum sadness that Brukhovich can achieve if he performs no more than $$$k$$$ operations.
As a reminder, the greatest common divisor (GCD) of two non-negative integers $$$x$$$ and $$$y$$$ is the maximum integer that is a divisor of both $$$x$$$ and $$$y$$$ and is denoted as $$$gcd(x, y)$$$. In particular, $$$gcd(x, 0) = gcd(0, x) = x$$$ for any non-negative integer $$$x$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 10^5$$$) — the total number of exams and the maximum number of exams that can be simplified, respectively.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$ — the elements of array $$$a$$$, which are the difficulties of the exams ($$$0 \leq a_i \leq 10^9$$$).
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$10^5$$$.
For each test case, output the minimum possible sadness that can be achieved by performing no more than $$$k$$$ operations.
95 21 3 5 7 95 23 5 7 9 118 217 15 10 1 1 5 14 85 31 1 1 1 15 51 1 1 1 119 71 1 2 3 4 5 5 6 6 7 8 9 10 1 1 1 2 3 115 62 1 1 1 1 2 1 1 2 1 1 1 2 1 25 21 1 1 1 25 21 0 1 0 1
1 0 2 2 0 5 5 2 1
In the first test case, a sadness of $$$1$$$ can be achieved. To this, you can simplify the second and fourth exams. After this, there will be only one pair of adjacent exams with a greatest common divisor (GCD) equal to one, which is the first and second exams.
In the second test case, a sadness of $$$0$$$ can be achieved by simplifying the second and fourth exams.
You are given a rooted tree with the root at vertex $$$1$$$, initially consisting of a single vertex. Each vertex has a numerical value, initially set to $$$0$$$. There are also $$$q$$$ queries of two types:
After all queries, output the numerical value of all of the vertices in the final tree.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^4$$$) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains a single integer $$$q$$$ ($$$1 \leq q \leq 5 \cdot 10^5$$$) — the number of queries.
The following $$$q$$$ lines can fall into two cases:
It is guaranteed that the sum of $$$q$$$ across all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output the numerical value of each vertex of the final tree after all queries have been performed.
392 1 31 12 2 11 12 3 21 32 1 41 32 3 252 1 11 12 1 -11 12 1 151 11 12 1 12 1 32 2 10
7 5 8 6 2 1 0 1 4 14 4
In the first case, the final tree with the assigned numerical values will look like this:
The final tree with the assigned numerical values