text
stringlengths 0
801
|
---|
In the first test case, we can increase $c_1 = 1$ by $a = 5$. The array $c$ will become $[6, 3, 4, 4]$, and the range is $3$. Note that there is more than one way to reach the answer.
|
In the second test case, we can increase $c_1 = 1$ by $a = 2$ and then increase $c_1 = 3$ by $b = 3$. Also, we can increas
|
Let there be a set that contains distinct positive integers. To expand the set to contain as many integers as possible, Eri can choose two integers $x\neq y$ from the set such that their average $\frac{x+y}2$ is still a positive integer and isn't contained in the set, and add it to the set. The integers $x$ and $y$ remain in the set.
|
Let's call the set of integers consecutive if, after the elements are sorted, the difference between any pair of adjacent elements is $1$. For example, sets $\\{2\\}$, $\\{2, 5, 4, 3\\}$, $\\{5, 6, 8, 7\\}$ are consecutive, while $\\{2, 4, 5, 6\\}$, $\\{9, 7\\}$ are not.
|
Eri likes consecutive sets. Suppose there is an array $b$, then Eri puts all elements in $b$ into the set. If after a finite number of operations described above, the set can become consecutive, the array $b$ will be called brilliant.
|
Note that if the same integer appears in the array multiple times, we only put it into the set once, as a set always contains distinct positive integers.
|
Eri has an array $a$ of $n$ positive integers. Please help him to count the number of pairs of integers $(l,r)$ such that $1 \leq l \leq r \leq n$ and the subarray $a_l, a_{l+1}, \ldots, a_r$ is brilliant.
|
Each test consists of multiple test cases. 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 4 \cdot 10^5$) — 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^9$) — the elements of the array $a$.
|
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $4 \cdot 10^5$.
|
For each test case, output a single integer — the number of brilliant subarrays.
|
In the first test case, the array $a = [2, 2]$ has $3$ subarrays: $[2]$, $[2]$, and $[2, 2]$. For all of them, the set only contains a single integer $2$, therefore it's always consecutive. All these subarrays are bril
|
A beautiful binary matrix is a matrix that has ones on its edges and zeros inside.
|
 Examples of four beautiful binary matrices.
|
Today, Sakurako was playing with a beautiful binary matrix of size $r \times c$ and created a binary string $s$ by writing down all the rows of the matrix, starting from the first and ending with the $r$-th. More formally, the element from the matrix in the $i$-th row and $j$-th column corresponds to the $((i-1)*c+j)$-th element of the string.
|
You need to check whether the beautiful matrix from which the string $s$ was obtained could be squared. In other words, you need to check whether the string $s$ could have been build from a square beautiful binary matrix (i.e., one where $r=c$).
|
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the string.
|
The second line of each test case contains the string $s$ of length $n$. The string is always the result of writing out the strings of a beautiful matrix.
|
It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
|
Print "Yes", if the original matrix could have been square, and "No" otherwise.
|
For the second test case, string 1111 can be obtained from the matrix:
|
$1$| $1$ ---|--- $1$| $1$ For the third test case, string 111101111 can be obtained from the matrix:
|
$1$| $1$| $1$ ---|---|--- $1$| $0$| $1$ $1$| $1$| $1$ There is no square matrix in the fourth case, such that the string can be obtained from it.
|
Sakurako really loves alternating strings. She calls a string $s$ of lowercase Latin letters an alternating string if characters in the even positions are the same, if characters in the odd positions are the same, and the length of the string is even.
|
For example, the strings 'abab' and 'gg' are alternating, while the strings 'aba' and 'ggwp' are not.
|
As a good friend, you decided to gift such a string, but you couldn't find one. Luckily, you can perform two types of operations on the string:
|
1. Choose an index $i$ and delete the $i$-th character from the string, which will reduce the length of the string by $1$. This type of operation can be performed no more than $1$ time; 2. Choose an index $i$ and replace $s_i$ with any other letter.
|
Since you are in a hurry, you need to determine the minimum number of operations required to make the string an alternating one.
|
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
The first line of each test case contains a single number $n$ ($1 \le n\le 2\cdot 10^5$) — the length of the string.
|
The second line of each test case contains a string $s$, consisting of lowercase Latin letters.
|
It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output a single integer — the minimum number of operations required to turn the string $s$ into an alternating one.
|
For the string ababa, you can delete the first character to get baba, which is an alternating string.
|
For the string acdada, you can change the first two characters to get dadada, which is an alternating string.
|
Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.
|
Believing in the strength of his password, Mansur stated that his password — is a binary string of length $n$. He is also ready to answer Dimash's questions of the following type:
|
Dimash says a binary string $t$, and Mansur replies whether it is true that $t$ is a substring of his password.
|
Help Dimash find out the password in no more than $2n$ operations; otherwise, Mansur will understand the trick and stop communicating with him.
|
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
|
In the first example, the string $010$ is given. Therefore, the answers to the queries are as follows:
|
"? 00" $00$ is not a substring of $010$, so the answer is $0$.
|
"? 000" $000$ is not a substring, so the answer is $0$.
|
"? 010" $010$ is a substring, so the answer is $1$.
|
In the second example, the string is $1100$, in the third $0110$, and in the fourth $10$.
|
In Sherwood, we judge a man not by his wealth, but by his merit.
|
Look around, the rich are getting richer, and the poor are getting poorer. We need to take from the rich and give to the poor. We need Robin Hood!
|
There are $n$ people living in the town. Just now, the wealth of the $i$-th person was $a_i$ gold. But guess what? The richest person has found an extra pot of gold!
|
More formally, find an $a_j=max(a_1, a_2, \dots, a_n)$, change $a_j$ to $a_j+x$, where $x$ is a non-negative integer number of gold found in the pot. If there are multiple maxima, it can be any one of them.
|
A person is unhappy if their wealth is strictly less than half of the average wealth$^{\text{∗}}$.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.