text
stringlengths
0
801
For each test case, output a single integer: the maximum possible size of a deck if you operate optimally.
In the first test case, you can buy one card with the number $1$, and your cards become $[1, 1, 1, 1, 2, 2, 3, 3]$. You can partition them into the decks $[1, 2], [1, 2], [1, 3], [1, 3]$: they all have size $2$, and they all contain distinct values. You can show that you cannot get a partition with decks of size greater than $2$, so the answer is $2$.
In the second test case, you can buy two cards with the number $1$ and o
Mocha likes arrays, so before her departure, Bazoka gave her an array $a$ consisting of $n$ positive integers as a gift.
Now Mocha wants to know whether array $a$ could become sorted in non- decreasing order after performing the following operation some (possibly, zero) times:
* Split the array into two parts — a prefix and a suffix, then swap these two parts. In other words, let $a=x+y$. Then, we can set $a:= y+x$. Here $+$ denotes the array concatenation operation.
For example, if $a=[3,1,4,1,5]$, we can choose $x=[3,1]$ and $y=[4,1,5]$, satisfying $a=x+y$. Then, we can set $a:= y + x = [4,1,5,3,1]$. We can also choose $x=[3,1,4,1,5]$ and $y=[\,]$, satisfying $a=x+y$. Then, we can set $a := y+x = [3,1,4,1,5]$. Note that we are not allowed to choose $x=[3,1,1]$ and $y=[4,5]$, neither are we allowed to choose $x=[1,3]$ and $y=[5,1,4]$, as both these choices do not satisfy $a=x+y$.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 1000$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($2\leq n\leq 50$) — the length of the array $a$.
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\leq a_i \leq 10^6$) — the elements of array $a$.
For each test case, output "Yes" if $a$ could become non-decreasing after performing the operation any number of times, and output "No" if not.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response).
In the first test case, it can be proven that $a$ cannot become non- decreasing after performing the operation any number of times.
In the second test case, we can perform the following operations to make $a$ sorted in non-decreasing order:
* Split the array into two parts: $x=[7]$ and $y=[9,2,2,3]$, then swap these two parts. The array will become $y+x = [9,2,2,3,7]$. * Split the array into two parts: $x=[9]$ and $y=[2,2,3,7]$, then swap the
[EnV - The Dusty Dragon Tavern](https://soundcloud.com/envyofficial/env-the- dusty-dragon-tavern)
You are given an array $a_1, a_2, \ldots, a_n$ of positive integers.
You can color some elements of the array red, but there cannot be two adjacent red elements (i.e., for $1 \leq i \leq n-1$, at least one of $a_i$ and $a_{i+1}$ must not be red).
Your score is the maximum value of a red element, plus the minimum value of a red element, plus the number of red elements. Find the maximum score you can get.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). 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 length of the array.
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 given array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
For each test case, output a single integer: the maximum possible score you can get after coloring some elements red according to the statement.
In the first test case, you can color the array as follows: $[\color{red}{5}, 4, \color{red}{5}]$. Your score is $\max([5, 5]) + \min([5, 5]) + \text{size}([5, 5]) = 5+5+2 = 12$. This is the maximum score you can get.
In the second test case, you can color the array as follows: $[4, \color{red}{5}, 4]$. Your score is $\max([5]) + \min([5]) + \text{size}([5]) = 5+5+1 = 11$. This is the maximum score you can get.
In the third test case, you can color the array as follows: $[\color{red}{3}, 3, \color{red}{3}, 3, \color{red}{4}, 1, 2, \color{red}{3}, 5, \color{red}{4}]$. Your score is $\max([3, 3, 4, 3, 4]) + \min([3, 3, 4, 3, 4]) + \text{size}([3, 3, 4, 3, 4]) = 4+3+5 = 12$. This is the maximum score you can get.
[Ken Arai - COMPLEX](https://soundcloud.com/diatomichail2/complex)
This is the hard version of the problem. In this version, the constraints on $n$ and the time limit are higher. You can make hacks only if both versions of the problem are solved.
A set of (closed) segments is complex if it can be partitioned into some subsets such that
* all the subsets have the same size; and * a pair of segments intersects if and only if the two segments are in the same subset.
You are given $n$ segments $[l_1, r_1], [l_2, r_2], \ldots, [l_n, r_n]$. Find the maximum size of a complex subset of these segments.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of segments.
The second line of each test case contains $n$ integers $l_1, l_2, \ldots, l_n$ ($1 \le l_i \le 2n$) — the left endpoints of the segments.
The third line of each test case contains $n$ integers $r_1, r_2, \ldots, r_n$ ($l_i \leq r_i \le 2n$) — the right endpoints of the segments.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
For each test case, output a single integer: the maximum size of a complex subset of the given segments.
In the first test case, all pairs of segments intersect, therefore it is optimal to form a single group containing all of the three segments.
In the second test case, there is no valid partition for all of the five segments. A valid partition with four segments is the following: $\\{\\{ [1, 5], [2, 4] \\}, \\{ [6, 9], [8, 10] \\}\\}$.
In the third test case, it is optimal to make a single group containing all the segments except the second.
[NightHawk22 - Isolation](https://soundcloud.com/vepium/nighthawk22-isolation- official-limbo-remix)
This is the medium version of the problem. In the three versions, the constraints on $n$ and the time limit are different. You can make hacks only if all the versions of the problem are solved.
This is the statement of Problem D1B:
* There are $n$ cities in a row, numbered $1, 2, \ldots, n$ left to right. * At time $1$, you conquer exactly one city, called the starting city. * At time $2, 3, \ldots, n$, you can choose a city adjacent to the ones conquered so far and conquer it.
You win if, for each $i$, you conquer city $i$ at a time no later than $a_i$. A winning strategy may or may not exist, also depending on the starting city. How many starting cities allow you to win?
For each $0 \leq k \leq n$, count the number of arrays of positive integers $a_1, a_2, \ldots, a_n$ such that
* $1 \leq a_i \leq n$ for each $1 \leq i \leq n$; * the answer to Problem D1B is $k$.
The answer can be very large, so you have to calculate it modulo a given prime $p$.