There are $$$n$$$ SWERC candidates in USI and we are going to hold a contest for them. Each of the candidates has a consecutive free period to do the contest. For the $$$i$$$-th candidate, he/she is available from the $$$l_i$$$-th slot to $$$r_i$$$-th slot. The question is, is there a slot that everyone is free so we can do the contest at that time?
The first line contains an integer $$$T(1 \le T \le 10^3)$$$ — the number of test cases. The description of the test cases follows.
For each test case, the first line contains an integer $$$n(1 \le n \le 10^3)$$$ — the number of candidates.
The next $$$n$$$ lines contains two integers $$$l_i,r_i(1 \le l_i \le r_i \le 10^3)$$$ — the free time period of $$$i$$$-th candidate.
It is guaranteed that $$$\sum n \le 10^3$$$ for all test cases.
For each test case, print "YES"(without quotes) in a line if there is at least one slot in which every candidate is available. Otherwise, print "NO"(without quotes) in a line.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
231 31 22 331 22 33 4
YES NO
For the first test case in the sample, everyone is available at slot $$$2$$$.
For the second test case in the sample, there's no slot that everyone is available.
Boboge is currently at $$$(x_1, y_1)(y_1 \gt 0)$$$, there is a river at $$$y=0$$$, and his destination is at $$$(x_2, y_2)(y_2 \gt 0)$$$. He needs to get some water from the river first, then go to the destination. What's the minimum distance he has to travel?
A example. The first line contains an integer $$$T(1 \le T \le 10^5)$$$ — the number of test cases. The description of the test cases follows.
The only line of each test case consists of $$$4$$$ integers: $$$x_1,y_1,x_2,y_2(-10^9 \le x_1, x_2 \le 10 ^ 9, 0 \lt y_1, y_2 \le 10^9)$$$ — the positions.
For each test case, print the minimum distance.
Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.
Formally, let your answer be $$$x$$$, and the jury's answer be $$$y$$$. Your answer is accepted if and only if $$$\frac{|x-y|}{max(1,|y|)} \le 10^{-6}$$$.
20 1 2 1-10 10 -20 20
2.8284271247 31.6227766017
1-1000000000 1000000000 1000000000 1000000000
2828427124.7461900711
jiangly is pretty good at competitive programming.
Now, there are $$$n$$$ professors, each giving a grade for jiangly's competitive programming skills. The $$$i$$$-th professor gives a grade of $$$a_i$$$.
If we sort all the grades and delete the first and the last ones (minimum and maximum), the sum of the rest grades would be the final grade for jiangly. Formally, if array $$$b$$$ are the sorted grades, the final grade is:
$$$$$$ \sum_{i=2}^{n-1}{b_i} $$$$$$
If you talk to some professor about this fact, the grade this professor will give to jiangly would rise a little bit. If you talk to $$$i$$$-th professor, $$$a_i$$$ will becomes to $$$d_i(a_i \lt d_i)$$$.
You do not have much time, so you can only talk to one professor about the fact.
As you want the grade to be fair, you want to maximize jiangly's grade. Note that we sort the grades after you talk to a professor.
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.
For each test case, the first line consists of a single integer $$$n(3 \le n \le 10^5)$$$ — the number of professors.
For each test case, the second line consists of $$$n$$$ integers $$$a_1, a_2, \dots, a_n(1 \le a_i \le 10^3)$$$ — the initial grade given.
For each test case, The third line consists of $$$n$$$ integers $$$d_1, d_2, \dots, d_n(a_i \lt d_i \le 10^3)$$$ — the new grade after you talk to some professor.
It is guaranteed that $$$\sum n \le 10^5$$$ for all test cases.
For each test case, print a single integer in a line — the maximum grade that jiangly can get in the end.
161 1 4 5 1 42 2 5 6 2 5
11
For case in the example, you can choose talk to the $$$3$$$-rd professor, the final grades are: $$$[1, 1, 5, 5, 1, 4]$$$, the sum of grades after delete is $$$1 + 1 + 4 + 5 = 11$$$.
You are given an array of length $$$n$$$ consisting of positive integers that do not exceed $$$m$$$.
You have $$$2^n - 1$$$ ways to choose a non-empty subsequence of the array.
For each $$$x \in [1, m]$$$, how many ways you can choose a non-empty subsequence $$$b$$$ of $$$a$$$ that:
$$$$$$ gcd(b_1, b_2, ...) = x $$$$$$
The greatest common divisor $$$gcd(a,b,c, \dots)$$$ of multiple positive integers is equal to the biggest integer $$$d$$$ such that all integers $$$a,b,c,\dots$$$ are divisible by $$$d$$$.
You have to print the answer for every $$$x$$$, since the answer could be huge, print the answer taken modulo $$$998244353$$$. If you get the same subsequence with different choices, they are considered to be different.
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(1 \le n \le 10^6)$$$ and $$$m(1 \le m \le 10^6)$$$ — the length of the array and the limit of array elements.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n(1 \le a_i \le m)$$$ — the elements of the array.
It is guaranteed that $$$\sum n \le 10^6$$$ and $$$\sum m \le 10^6$$$ for all test cases.
For each test case, print $$$m$$$ integers in a line, which is explained above.
16 51 1 4 5 1 4
59 0 0 3 1
110 103 1 2 2 6 7 6 5 8 3
978 27 12 0 1 3 1 1 0 0
110 101 2 3 4 5 6 7 8 9 10
983 26 5 2 2 1 1 1 1 1
For the case in the first sample, there are $$$2^6 - 1 = 63$$$ ways to select a subsequence.
The only way to achieve $$$gcd=5$$$ is to choose subsequence $$$[5]$$$.
To achieve $$$gcd=4$$$, you can choose $$$[4]$$$ or $$$[4, 4]$$$, there are two ways to have $$$[4]$$$.
The rest subsequences have $$$gcd=1$$$.
You are given a random generated tree rooted at $$$1$$$ with $$$n$$$ vertices and some queries. Here a tree is a connected graph in which there are no cycles.
Each vertex of the tree has a weight $$$W_i$$$.
Each query has $$$2$$$ vertices $$$(u, v)$$$. For each query, assume that array $$$a$$$ is the path from $$$1$$$ to $$$u$$$, and array $$$b$$$ is the path from $$$1$$$ to $$$v$$$, find $$$2$$$ subsequence with equal length from $$$a$$$ and $$$b$$$ respectively as $$$c$$$ and $$$d$$$, maximize the following value:
$$$$$$ \sum_{i=1}^{size_c} W_{c_i} \times W_{d_i} $$$$$$
The tree itself is generated as follows:
Generate_tree(n):
for i := 2 -> n
father[i] := random choose an integer from [1, i - 1]
return father
p.s. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.
The first line of the input consists of one single integer $$$n (1 \le n \le 10^5)$$$ — the size of the tree, note that $$$n$$$ is not randomly generated.
The next line consists of $$$n$$$ integers: $$$W_1,W_2, \dots ,W_n(1 \le W_i \le 10^6)$$$ — the weight of each vertex.
The next line consists of $$$n-1$$$ integers: $$$p_2, p_3, \dots , p_n(1 \le p_i \lt i)$$$ — $$$p_i$$$ denotes the father of vertex $$$i$$$. We start from vertex $$$2$$$, as vertex $$$1$$$ is the root.
The next line consists of one integer $$$q (1 \le q \le 10^5)$$$ — the number of queries.
The next $$$q$$$ lines, each consists of two integers $$$u,v(1 \le u,v \le n)$$$ — denoting a query.
For each query, print the maximum value as described above in a line.
31 100 1001 112 3
10001
For the query in Example, path $$$a$$$ equals to $$$[1, 2]$$$, path $$$b$$$ equals to $$$[1, 3]$$$, we can make $$$c=a$$$ and $$$d=b$$$, we get $$$1 \times 1 + 100 \times 100 = 10001$$$.
You are given an array $$$a$$$ with length $$$n$$$.
To make an array beautiful, you must make it as short as possible. What you can do is choose a pair of adjacent elements, provided they are different. After you delete the pair, there may be a new pair that becomes adjacent. e.g. If you delete $$$a_2$$$ and $$$a_3(a_2 \neq a_3)$$$, $$$a_1$$$ and $$$a_4$$$ will become adjacent. After the removals, the minimum length of the array can be achieved is the beauty of the original array.
For example, the beauty of the array $$$[1, 1, 2, 2]$$$ is $$$0$$$, as you can delete element in position $$$2$$$ and $$$3$$$, and the array becomes $$$[1, 2]$$$, then you can make it empty.
However, this could be too easy, so you are also given $$$q$$$ queries. Each query consists of two integers $$$(l,r)$$$, denotes that you need output the beauty of array $$$[a_l,a_{l+1},\dots,a_{r-1},a_r]$$$.
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.
For each test case, the first line consists of a single integer $$$n(1 \le n \le 10^5)$$$ — the length of the array.
The next line consists of $$$n$$$ integers $$$a_i(1 \le a_i \le n)$$$ — the array $$$a$$$.
The next line contains an integer $$$q(1 \le q \le 10^5)$$$ — the number of queries.
The following $$$q$$$ line each consists of two integers $$$l, r(1 \le l \le r \le n)$$$ — the interval that is being queried.
It is guaranteed that $$$\sum n \le 10^5$$$ and $$$\sum q \le 10^5$$$ for all test cases.
For each query, output a single integer in a line — the beauty of the interval.
141 1 2 241 41 31 11 2
0 1 1 2
Note that we are only doing the query for the beauty, we don't remove any elements in fact.
For the first sample,
$$$l=1,r=4$$$, The whole array can be removed as described above.
$$$l=1,r=3$$$, The queried array is $$$[1, 1, 2]$$$. You can remove elements in position $$$2$$$ and $$$3$$$ and the array becomes $$$[1]$$$.
$$$l=1,r=2$$$, The queried array is $$$[1, 1]$$$. You can not do any removal.