text stringlengths 0 801 |
|---|
In the third test case, you can perform the following operations: $\mathtt{1}\underline{\mathtt{10}}\mathtt{1}\xrightarrow{r_1=\mathtt{0}} \mathtt{1}\underline{\mathtt{01}} \xrightarrow{r_2=\mathtt{0}} \underline{\mathtt{10}} \xri |
You are given a cycle with $n$ vertices numbered from $0$ to $n-1$. For each $0\le i\le n-1$, there is an undirected edge between vertex $i$ and vertex $((i+1)\bmod n)$ with the color $c_i$ ($c_i=\texttt{R}$ or $\texttt{B}$). |
Determine whether the following condition holds for every pair of vertices $(i,j)$ ($0\le i<j\le n-1$): |
* There exists a palindrome route between vertex $i$ and vertex $j$. Note that the route may not be simple. Formally, there must exist a sequence $p=[p_0,p_1,p_2,\ldots,p_m]$ such that: * $p_0=i$, $p_m=j$; * For each $0\leq x\le m-1$, either $p_{x+1}=(p_x+1)\bmod n$ or $p_{x+1}=(p_{x}-1)\bmod n$; * For ... |
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$) — the number of test cases. The description of the test cases follows. |
The first line of each test case contains an integer $n$ ($3\leq n\leq10^6$) — the number of vertices in the cycle. |
The second line contains a string $c$ of length $n$ ($c_i=\texttt{R}$ or $\texttt{B}$) — the color of each edge. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$. |
For each test case, print "YES" (without quotes) if there is a palindrome route between any pair of nodes, and "NO" (without quotes) otherwise. |
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. |
In the first test case, it is easy to show that there is a palindrome route between any two vertices. |
In the second test case, for any two vertices, there exists a palindrome route with only red edges. |
In the third test case, the cycle is as follows: $0\color{red}{\overset{\texttt{R}}{\longleftrightarrow}}1\color{blue}{\overset{\texttt{B}}{\longleftrightarrow}}2\color{blue}{\overset{\texttt{B}}{\longleftrightarrow}}3\color{red}{\overset{\t |
For an arbitrary binary string $t$$^{\text{∗}}$, let $f(t)$ be the number of non-empty subsequences$^{\text{†}}$ of $t$ that contain only $\mathtt{0}$, and let $g(t)$ be the number of non-empty subsequences of $t$ that contain at least one $\mathtt{1}$. |
Note that for $f(t)$ and for $g(t)$, each subsequence is counted as many times as it appears in $t$. E.g., $f(\mathtt{000}) = 7, g(\mathtt{100}) = 4$. |
We define the oneness of the binary string $t$ to be $|f(t)-g(t)|$, where for an arbitrary integer $z$, $|z|$ represents the absolute value of $z$. |
You are given a positive integer $n$. Find a binary string $s$ of length $n$ such that its oneness is as small as possible. If there are multiple strings, you can print any of them. |
$^{\text{∗}}$A binary string is a string that only consists of characters $\texttt{0}$ and $\texttt{1}$. |
$^{\text{†}}$A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements. For example, subsequences of $\mathtt{1011101}$ are $\mathtt{0}$, $\mathtt{1}$, $\mathtt{11111}$, $\mathtt{0111}$, but not $\mathtt{000}$ nor $\mathtt{11100}$. |
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. |
The only line of each test case contains an integer $n$ ($1 \leq n \leq 2\cdot10^5$) — the length of $s$. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$. |
For each test case, output $s$ on a new line. If multiple answers exist, output any. |
In the first test case, for the example output, $f(t)=1$ because there is one subsequence that contains only $\mathtt{0}$ ($\mathtt{0}$), and $g(t)=0$ because there are no subsequences that contain at least one $1$. The oneness is $|1-0|=1$. The output $\mathtt{1}$ is correct as well because its oneness is $|0-1|=1$. |
For the example output of the second test case, $f(t)=1$ because there is one non-empty subsequence that contains only $\mathtt{0}$, and $g(t)=2$ because there are two non-empty subs |
Alice and Bob are playing a game. There is a list of $n$ booleans, each of which is either true or false, given as a binary string $^{\text{∗}}$ of length $n$ (where $\texttt{1}$ represents true, and $\texttt{0}$ represents false). Initially, there are no operators between the booleans. |
Alice and Bob will take alternate turns placing and or or between the booleans, with Alice going first. Thus, the game will consist of $n-1$ turns since there are $n$ booleans. Alice aims for the final statement to evaluate to true, while Bob aims for it to evaluate to false. Given the list of boolean values, determine... |
To evaluate the final expression, repeatedly perform the following steps until the statement consists of a single true or false: |
* If the statement contains an and operator, choose any one and replace the subexpression surrounding it with its evaluation. * Otherwise, the statement contains an or operator. Choose any one and replace the subexpression surrounding the or with its evaluation. |
For example, the expression true or false and false is evaluated as true or (false and false) $=$ true or false $=$ true. It can be shown that the result of any compound statement is unique. |
$^{\text{∗}}$A binary string is a string that only consists of characters $\texttt{0}$ and $\texttt{1}$ |
The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases. |
The first line of each test case contains an integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the length of the string. |
The second line contains a binary string of length $n$, consisting of characters $\texttt{0}$ and $\texttt{1}$ — the list of boolean values. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. |
For each testcase, output "YES" (without quotes) if Alice wins, and "NO" (without quotes) otherwise. |
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response). |
In the first |
Suppose we partition the elements of an array $b$ into any number $k$ of non-empty multisets $S_1, S_2, \ldots, S_k$, where $k$ is an arbitrary positive integer. Define the score of $b$ as the maximum value of $\operatorname{MEX}(S_1)$$^{\text{∗}}$$ + \operatorname{MEX}(S_2) + \ldots + \operatorname{MEX}(S_k)$ over all... |
Envy is given an array $a$ of size $n$. Since he knows that calculating the score of $a$ is too easy for you, he instead asks you to calculate the sum of scores of all $2^n - 1$ non-empty subsequences of $a$.$^{\text{†}}$ Since this answer may be large, please output it modulo $998\,244\,353$. |
$^{\text{∗}}$$\operatorname{MEX}$ of a collection of integers $c_1, c_2, \ldots, c_k$ is defined as the smallest non-negative integer $x$ that does not occur in the collection $c$. For example, $\operatorname{MEX}([0,1,2,2]) = 3$ and $\operatorname{MEX}([1,2,2]) = 0$ |
$^{\text{†}}$A sequence $x$ is a subsequence of a sequence $y$ if $x$ can be obtained from $y$ by deleting several (possibly, zero or all) elements. |
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. |
The first line of each test case contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of $a$. |
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i < n$) — the elements of the array $a$. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. |
For each test case, output the answer, modulo $998\,244\,353$. |
In the first testcase, we must consider seven subsequences: |
* $[0]$: The score is $1$. * $[0]$: The score is $1$. * $[1]$: The score is $0$. * $[0,0]$: The score is $2$. * $[0,1]$: The score is $2$. * $[0,1]$: The score is $2$. * $[0,0,1]$: The score is $3$. |
The answer for the first testcase is $1+1+2+2+2+3=11$. |
In the last testcase, all subsequences have a score of $0$. |
This is the hard version of the problem. In this version, $n \leq 10^6$. You can only make hacks if both versions of the problem are solved. |
Orangutans are powerful beings—so powerful that they only need $1$ unit of time to destroy every vulnerable planet in the universe! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.