The world is full of colors.
When creating an artwork, painters often use the technique of complementary colors to make their works more visually striking. In the $$$\mathtt{RGB}$$$ color model, complementary colors have a clear special property when represented as color codes.
Specifically, in the $$$\mathtt{RGB}$$$ color model, a color code consists of a $$$\mathtt{\#}$$$ followed by the hexadecimal representations of its $$$\mathtt{R}$$$ (red), $$$\mathtt{G}$$$ (green), and $$$\mathtt{B}$$$ (blue) values concatenated together. The values of $$$\mathtt{R}$$$, $$$\mathtt{G}$$$, and $$$\mathtt{B}$$$ all range from $$$[0, 255]$$$. For example, the color code $$$\mathtt{\#1f1e33}$$$ represents a very dark purple. Its $$$\mathtt{R}$$$, $$$\mathtt{G}$$$, and $$$\mathtt{B}$$$ values in hexadecimal are $$$1f$$$, $$$1e$$$, $$$33$$$, and in decimal are $$$31$$$, $$$30$$$, $$$51$$$. In particular, if any of the hexadecimal representations of $$$\mathtt{R}$$$, $$$\mathtt{G}$$$, or $$$\mathtt{B}$$$ has fewer than two digits, a leading $$$0$$$ must be added. For example, the color code for black is $$$\mathtt{\#000000}$$$.
We define two colors to be complementary colors if and only if their $$$\mathtt{R}$$$, $$$\mathtt{G}$$$, and $$$\mathtt{B}$$$ values satisfy that each corresponding pair sums to $$$255$$$.
Whalica landed on a colorless planet during her interstellar voyage. She wanted to bring more vitality and visual impact to the planet by adding color to it, so she first thought of a color. Can you provide the complementary color of that color?
The first line contains an integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The next $$$t$$$ lines each contain a string $$$s$$$ — the color code of the color Whalica came up with.
It is guaranteed that all input color codes are valid $$$\mathtt{RGB}$$$ color codes.
For each test case, output a string — the color code of the complementary color of the given color.
Note: The output is case-sensitive. When printing the color code, please use lowercase letters rather than uppercase letters.
2#1f1e33#114514
#e0e1cc#eebaeb
Whalica has a mysterious permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$. Let $$$$$$ S_k = \sum_{i = 1}^{k} p_i $$$$$$ If for all $$$1 \le i \le n$$$, $$$S_i$$$ is divisible by $$$p_i$$$, then the permutation $$$p$$$ is called a good permutation.
Checking whether a permutation is a good permutation is far too easy, and Whalica would never enjoy doing something that simple. Therefore, Whalica has specially prepared another problem for you:
Given a positive integer $$$n$$$, you need to construct a permutation $$$p$$$ of length $$$n$$$ such that it is a good permutation. You need to determine whether such a permutation exists. Moreover, if such a permutation exists, output any one permutation that satisfies the condition.
$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains an integer $$$n$$$ ($$$1 \le n \le 5 \times 10^5$$$) — the length of the permutation you need to construct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, the first line contains a string indicating whether such a permutation can be constructed. If it is possible, output $$$\mathtt{YES}$$$; otherwise, output $$$\mathtt{NO}$$$.
If such a permutation can be constructed, output any one permutation that satisfies the conditions on the second line.
Note that the output is case-sensitive.
3134
YES1YES2 1 3YES3 1 4 2
"The so-called Shichieichou (Seven-Shadow Butterflies) are the fragments of human memory..."
"The 'memories' of those who left behind attachments or regrets during their lifetime exist in this world in the form of butterflies."
"...Even though they are just memories, these are things that should not remain in this world."
"Someone must guide them back to where they truly belong."
"This is the Yamanomatsuri (Mountain Festival), which has been managed by the Sorakado family for generations."
"...There is one specific memory that I must find, no matter what..."
To fulfill the duties of the Sorakado family and to find that indispensable memory, Sorakado Ao needs to guide the Shichieichou scattered across the mountain toward the "Mayoi no Tachibana" (The Lost Mandarin Orange) during the Yamanomatsuri.
The mountain paths of Torishirojima can be represented as a tree$$$^{\text{∗}}$$$ with $$$n$$$ nodes, rooted at node $$$1$$$. It is guaranteed that every leaf node in the tree has the same depth (i.e., the distance to the root).
Due to the rugged mountain paths and the deep night, Ao's movement must follow these rules:
To allow as many Shichieichou as possible to return, please tell Ao the maximum number of butterflies she can guide.
$$$^{\text{∗}}$$$A tree with $$$n$$$ vertices is an undirected connected graph with $$$n$$$ vertices and $$$n-1$$$ edges. A rooted tree is a tree in which one of the vertices is special and is called the root.
Each test contains multiple test cases. The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), representing the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases and the sum of $$$m$$$ over all test cases do not exceed $$$2 \times 10^5$$$. It is also guaranteed that the given edges form a tree, and that all leaf nodes have the same depth.
For each test case, output a single integer representing the maximum number of Shichieichou Ao can guide.
33 21 21 33 01 16 31 21 32 42 53 66 12 11 18 51 21 32 43 64 56 76 85 24 26 83 11 5
223
In the first test case, the tree is rooted at node $$$1$$$, and nodes $$$2$$$ and $$$3$$$ are both leaves. Starting from node $$$3$$$, one Seven-Shadow Butterfly can be guided at time $$$t=0$$$. Then, moving to node $$$1$$$, another butterfly can be guided at time $$$t=1$$$. Therefore, the answer is $$$2$$$.
Whalica has $$$n$$$ fans who are invited to join Whalica's lottery game.
Whalica stipulates that only non-empty strings consisting only of the characters $$$\mathtt{a, c, h, i, l, w}$$$ can be winning strings. Before the game starts, each fan writes down a valid guess string $$$s_i$$$.
There are $$$q$$$ events in total. For the $$$i$$$-th event, one of the following happens:
Whalica is too lazy and just wants to rest. Can you help her compute how many Whalica coins she needs to pay out for each draw event?
The first line contains two integers $$$n$$$, $$$q$$$ $$$(1 \le n, q \le 10^5)$$$ — the number of fans and the number of events.
Each of the next $$$n$$$ lines contains a fan's initial guess string $$$s_i$$$ $$$(1 \le |s_i| \le 10^5)$$$.
Each of the next $$$q$$$ lines contains an integer $$$op_i \in \{1,2\}$$$ — the event type.
It is guaranteed that the total sum of $$$|s_i|$$$ and the total sum of $$$|T_i|$$$ do not exceed $$$10^5$$$, and that the character set of all strings is a subset of $$$\{\mathtt{a,c,h,i,l,w}\}$$$.
For each draw event, output the total number of Whalica coins Whalica needs to pay out.
3 3awaawhlicaalicawhalica1 awc21 licwlaawwl
5 7
To commemorate the eight-thousand-year wait, Iroha and Kaguya will edit an echo sequence inside the virtual space "Tsukuyomi". Whenever two echoes are perfectly in sync, the stage will light up with a flash. They want to know: how many echo sequences can make the stage flash exactly $$$k$$$ times?
More specifically, they are given an array $$$a$$$ of length $$$n$$$.
For a sequence $$$b$$$ of length $$$m$$$, define its number of flashes as $$$$$$ f\left(b\right) = \left|\left\{i | 1 \leq i \leq m - 1, b_i = b_{i+1}\right\}\right| $$$$$$ that is, the number of times two adjacent elements in the sequence are equal.
You need to compute, among the $$$2^n$$$ subsequences$$$^{\text{∗}}$$$ of $$$a$$$, how many subsequences $$$b$$$ have exactly $$$k$$$ flashes (i.e. $$$f\left(b\right) = k$$$). Since the answer may be very large, print it modulo $$$998244353$$$.
$$$^{\text{∗}}$$$A sequence $$$b$$$ is a subsequence of a sequence $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by the deletion of several (possibly, zero or all) elements.
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 two integers $$$n$$$, $$$k$$$ ($$$1 \leq n \leq 2 \times 10^5$$$, $$$0 \leq k \leq 200$$$) — the length of the array $$$a$$$ and the desired number of flashes.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n$$$ ($$$1 \leq a_i \leq n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output a single integer — the number of subsequences whose number of flashes is $$$k$$$, taken modulo $$$998244353$$$.
24 11 2 2 13 01 1 2
56
In the first test case, $$$a = [1, 2, 2, 1]$$$, and the $$$16$$$ subsequences are as follows:
To push magicology toward a more rigorous discipline, Anisphia and Euphyllia build a mana circuit network at the detached palace. The network forms a tree$$$^{\text{∗}}$$$ with $$$n$$$ vertices labeled $$$1, 2, \cdots, n$$$, and vertex $$$i$$$ stores a mana value $$$a_i$$$.
Root the tree at vertex $$$1$$$. For a vertex $$$u$$$, let $$$\mathrm{Subtree}\left(u\right)$$$ be the set of vertices in the subtree of $$$u$$$ (including $$$u$$$ itself and all of its descendants$$$^{\text{†}}$$$).
Define one operation $$$f$$$ on an array $$$x = \left(x_1, x_2, \cdots, x_n\right)$$$ by $$$y = f\left(x\right)$$$, where $$$$$$ y_u = \sum_{v \in \mathrm{Subtree}\left(u\right)} x_v $$$$$$
They apply the operation exactly $$$k$$$ times: let $$$x^{\left(0\right)} = a$$$, and $$$x^{\left(t\right)} = f\left(x^{\left(t - 1\right)}\right)$$$ for all $$$1 \leq t \leq k$$$.
Output $$$x^{\left(k\right)}_1, x^{\left(k\right)}_2, \cdots, x^{\left(k\right)}_n$$$ modulo $$$998244353$$$.
$$$^{\text{∗}}$$$A tree with $$$n$$$ vertices is an undirected connected graph with $$$n$$$ vertices and $$$n-1$$$ edges. A rooted tree is a tree in which one of the vertices is special and is called the root.
$$$^{\text{†}}$$$The descendants of vertex $$$u$$$ are all vertices $$$v$$$ such that $$$v \neq u$$$ and on the shortest path from the root to $$$v$$$, vertex $$$u$$$ is encountered.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n, k$$$ ($$$1 \le n \le 5000$$$, $$$0 \le k \le 10^{18}$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n$$$ ($$$0 \le a_i \lt 998244353$$$).
The next $$$n - 1$$$ lines of each test case contain two integers $$$u_i, v_i$$$ ($$$1 \le u_i, v_i \le n$$$) — two vertices that the $$$i$$$-th edge of the tree connects.
It is guaranteed that the given edges form a tree, and it is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, print $$$n$$$ integers $$$x^{\left(k\right)}_1, x^{\left(k\right)}_2, \cdots, x^{\left(k\right)}_n$$$ in one line, each taken modulo $$$998244353$$$.
35 21 2 3 4 51 33 43 51 26 10000000000000000003 1 4 1 5 91 22 32 44 54 63 110 20 301 23 2
38 2 21 4 5408356129 643450937 4 42549043 5 960 50 30
In the first test case, $$$a = [1, 2, 3, 4, 5]$$$, so $$$$$$ x^{\left(0\right)} = a = [1, 2, 3, 4, 5] $$$$$$ $$$$$$ x^{\left(1\right)} = f\left(x^{\left(0\right)}\right) = [x^{\left(0\right)}_1 + x^{\left(0\right)}_2 + x^{\left(0\right)}_3 + x^{\left(0\right)}_4 + x^{\left(0\right)}_5, x^{\left(0\right)}_2, x^{\left(0\right)}_3 + x^{\left(0\right)}_4 + x^{\left(0\right)}_5, x^{\left(0\right)}_4, x^{\left(0\right)}_5] = [15, 2, 12, 4, 5] $$$$$$ $$$$$$ x^{\left(2\right)} = f\left(x^{\left(1\right)}\right) = [x^{\left(1\right)}_1 + x^{\left(1\right)}_2 + x^{\left(1\right)}_3 + x^{\left(1\right)}_4 + x^{\left(1\right)}_5, x^{\left(1\right)}_2, x^{\left(1\right)}_3 + x^{\left(1\right)}_4 + x^{\left(1\right)}_5, x^{\left(1\right)}_4, x^{\left(1\right)}_5] = [38, 2, 21, 4, 5] $$$$$$
Retinal cone cells (Cone Cells) are mainly concentrated in the fovea of the macula and are responsible for color vision and high-resolution vision. Due to differences in their light absorption spectra, their distribution ratios are significantly asymmetric:
L-cones (long-wavelength / red): about 60% – 64%.
M-cones (medium-wavelength / green): about 30% – 32%.
S-cones (short-wavelength / blue): about 2% – 10%, and they are absent in the very center of the fovea.
This distribution explains why the human eye is most sensitive to green light (covered jointly by L and M cones), while its spatial resolution for pure blue is relatively low.
yyz likes the color blue. To find the most beautiful shade of blue, she keeps collecting it using magic. For a beautiful photo, yyz will first transform it into a blue Hilbert curve.
Specifically, there are $$$n$$$ color blocks arranged from left to right. The $$$i$$$-th block contains an amount of blue element $$$b_i$$$.
When yyz starts casting magic, she will give an incantation $$$\texttt{l r x}$$$, which means: extract all blocks in the array interval $$$[l, r]$$$ that satisfy $$$b_i \geq x$$$. After a block is extracted once, it will lose all of its blue elements.
Given $$$q$$$ magic casts, please tell yyz how many blue elements can be extracted each time.
The first line contains two integers $$$n, q$$$ ($$$1 \leq n, q \leq 2 \times 10^5$$$) — the number of blocks and the number of queries.
The second line contains $$$n$$$ integers $$$b_1, b_2, \cdots, b_n$$$ ($$$1 \leq b_i \leq 10^7$$$) — the amount of blue elements in the $$$i$$$-th block.
Each of the next $$$q$$$ lines contains three integers $$$l, r, x$$$ ($$$1 \leq l \leq r \leq n$$$, $$$1 \leq x \leq 10^7$$$) — a query interval and the threshold value.
Output $$$q$$$ lines. For each query, output one integer: the total amount of blue elements collected in the $$$i$$$-th magic operation.
3 486 91 703 3 562 3 11 1 761 2 52
70 91 86 0
yanami $$$\sim$$$
Whalica has a set $$$S$$$, and $$$S$$$ is initially empty. In addition, a parameter $$$n$$$ is given. You need to perform the given $$$q$$$ operations in order. There are four types of operations, and the format and meaning of each operation are as follows:
Operation $$$1$$$: $$$\texttt{1 x}$$$ Given an integer $$$x$$$ $$$(1\le x\le n)$$$, insert $$$x$$$ into the set $$$S$$$. In particular, if $$$S$$$ already contains the element $$$x$$$, then ignore this operation.
Operation $$$2$$$: $$$\texttt{2 x}$$$ Given an integer $$$x$$$ $$$(1\le x\le n)$$$, delete $$$x$$$ from the set $$$S$$$. In particular, if $$$S$$$ does not contain the element $$$x$$$, then ignore this operation.
Operation $$$3$$$: $$$\texttt{3}$$$ Query the smallest positive integer that does not appear in the set $$$S$$$.
Operation $$$4$$$: $$$\texttt{4}$$$ Query the weight of the set $$$S$$$. Here, the definition of the weight of the set $$$S$$$ is as follows: let the number of integers in the range $$$[1, n]$$$ that do not appear in the set $$$S$$$ be $$$k$$$, and let these $$$k$$$ elements in increasing order be $$$a_1, a_2, a_3, \cdots, a_k$$$, then the weight of the set $$$S$$$ is: $$$$$$ \sum_{i = 1}^{k} a_i \cdot 2^i $$$$$$ For each operation $$$4$$$, since the result may be very large, please take the result modulo $$$998244353$$$.
The first line contains two integers $$$n, q$$$ ($$$1\le n, q \le 10^5$$$) — the given parameter and the number of queries.
Next come $$$q$$$ queries, one per line. Please refer to the statement for the format and meaning.
For each operation $$$3$$$, output an integer, indicating the smallest positive integer that does not appear in the set $$$S$$$.
For each operation $$$4$$$, output an integer, indicating the weight of the set $$$S$$$, with the result taken modulo $$$998244353$$$.
5 71 11 21 22 22 334
2 128
Explanation for the example:
| Operation No. | Operation Type | Operation Result | Elements in the Set |
| 1 | Operation $$$1$$$ | Insert element $$$1$$$ | $$$\{1\}$$$ |
| 2 | Operation $$$1$$$ | Insert element $$$2$$$ | $$$\{1,2\}$$$ |
| 3 | Operation $$$1$$$ | The set $$$S$$$ already contains element $$$2$$$, ignore this operation | $$$\{1,2\}$$$ |
| 4 | Operation $$$2$$$ | Delete element $$$2$$$ | $$$\{1\}$$$ |
| 5 | Operation $$$2$$$ | The set $$$S$$$ does not contain element $$$3$$$, ignore this operation | $$$\{1\}$$$ |
| 6 | Operation $$$3$$$ | Query the smallest positive integer that does not appear in the set $$$S$$$, the result is $$$2$$$ | $$$\{1\}$$$ |
| 7 | Operation $$$4$$$ | Query the weight of the set $$$S$$$, the result is $$$2\times 2^1 + 3\times 2^2 + 4\times 2^3 + 5\times 2^4 = 4 + 12 + 32 + 80 = 128$$$ | $$$\{1\}$$$ |
At night, there are $$$n$$$ firefly lamps lit along the riverbank. The $$$i$$$-th lamp is located at coordinate $$$x_i$$$, and they are arranged from left to right along the river, i.e., $$$$$$ x_1 \lt x_2 \lt \cdots \lt x_n $$$$$$ XqAiyee wants to walk from the $$$1$$$-st lamp to the $$$n$$$-th lamp.
When she is at the $$$i$$$-th lamp ($$$1 \le i \le n-1$$$), she can choose:
Since the fireflies will get tired, XqAiyee can use "Fireflies lead the way" at most $$$k$$$ times.
Please determine the minimum stamina required for XqAiyee to reach the $$$n$$$-th lamp.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 2 \times 10^{5}$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$2 \leq n \leq 2 \times 10^5$$$, $$$0 \leq k \leq 200$$$) — the number of firefly lamps and the maximum number of times "Fireflies lead the way" can be used.
The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \cdots, x_n$$$ ($$$-10^5 \leq x_1 \lt x_2 \lt \cdots \lt x_n \leq 10^5$$$) — the coordinates of the lamps.
The third line of each test case contains $$$n - 1$$$ integers $$$a_1, a_2, \cdots, a_{n-1}$$$ ($$$0 \leq a_i \leq 10^5$$$).
The fourth line of each test case contains $$$n - 1$$$ integers $$$b_1, b_2, \cdots, b_{n-1}$$$ ($$$0 \leq b_i \leq 10^5$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output a single integer — the minimum stamina required for XqAiyee to reach the $$$n$$$-th lamp.
25 10 2 3 7 103 2 100 21 5 0 44 2-3 0 4 52 100 20 1 0
2320