Kaguya gives you two arrays $$$[a_1,a_2...a_n]$$$ and $$$[b_1,b_2...b_m]$$$, and you need to select two subsequences $$$[a_{c_1},a_{c_2}...a_{c_p}]$$$ and $$$[b_{d_1},b_{d_2}...b_{d_q}]$$$ that satisfy the following conditions:
Now she asks you whether no matter how you choose $$$[c_1,c_2...c_p]$$$, there exists a $$$[d_1,d_2...d_q]$$$ such that $$$[b_{d_1},b_{d_2}...b_{d_q}]$$$ is a subsequence of $$$[a_{c_1},a_{c_2}...a_{c_p}]$$$.
The first line contains the number of test cases $$$T$$$ $$$(1\le T\le 10^5)$$$ — the number of test cases.
For each case, the first line of each test case contains two integers $$$n,m$$$ $$$(1\le n,m\le 10^5)$$$.
The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1\le a_i\le 10^9)$$$.
The third line contains $$$m$$$ integers $$$b_i$$$ $$$(1\le b_i\le 10^9)$$$.
It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ are both not more than $$$10^5$$$.
For each test case, output "Yes"or "No".
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", and "YES" will be recognized as a positive response).
54 31 2 3 41 2 45 31 2 3 4 51 3 56 31 1 2 2 3 31 2 35 41 2 3 4 51 2 4 54 41 3 5 71 3 5 8
YES NO YES NO NO
In test $$$1$$$, there are a total of $$$5$$$ available subsequences of $$$[a_{c_1},a_{c_2}...a_{c_p}]$$$, each of which corresponds to one or more $$$[b_{d_1},b_{d_2}...b_{d_q}]$$$ so that $$$[b_{d_1},b_{d_2}...b_{d_q}]$$$ is a subsequence of $$$[a_{c_1},a_{c_2}...a_{c_p}]$$$.
| ID | Subsequence of $$$a_i$$$ | Subsequence of $$$b_i$$$ |
| $$$1$$$ | $$$[1,2,3,4]$$$ | $$$[1,4]$$$ |
| $$$2$$$ | $$$[1,2,4]$$$ | $$$[1,4]$$$ |
| $$$3$$$ | $$$[1,3,4]$$$ | $$$[1,4]$$$ |
| $$$4$$$ | $$$[2,3,4]$$$ | $$$[2,4]$$$ |
| $$$5$$$ | $$$[2,4]$$$ | $$$[2,4]$$$ |
In test $$$2$$$, if you choose $$$[a_{c_1},a_{c_2}...a_{c_p}]=[2,4,5]$$$, there is no solution for $$$b_i$$$.
123456zmy is playing GT: New Horizons and wants to build $$$n$$$ Bricked Blast Furnaces. A Bricked Blast Furnace is a multiblock structure. In this problem, we only consider the layer containing the Bricked Blast Furnace block.
Bricked Blast Furnace and the layer containing the block. We use 'B', 'F', and 'L' (or their lowercase) to represent Bricked Blast Furnace, Firebricks, and Lava, respectively. A complete Bricked Blast Furnace structure consists of 7 Firebricks, 1 Lava, and 1 Bricked Blast Furnace. The structure can be rotated arbitrarily, as shown below.
![]() | ![]() | ![]() | ![]() |
Multiple structures can share the same Firebricks 'F'. However, sharing 'B' or 'L' is not allowed. For example, there are 4 complete Bricked Blast Furnace structures below.
123456zmy wants to use no more than $$$3\times10^5$$$ Firebricks to form at least $$$n$$$ Bricked Blast Furnace structures. Please tell him how to arrange the blocks.
The input contains only one line with an integer $$$n$$$ $$$(1\le n\le 10^5)$$$, representing the number of Bricked Blast Furnace.
The first line of output contains an integer $$$k$$$ $$$(0\le k\le 10^6)$$$, representing the total number of blocks used.
The next $$$k$$$ lines each contain two integers $$$x$$$, $$$y$$$ and a character $$$c$$$, indicating the position and type of the block to be placed $$$(-10^{9}\le x,y \le 10^{9}, c\in\{$$$ 'B', 'b', 'F', 'f', 'L', 'l' $$$\})$$$.
You cannot place multiple blocks at the same position, i.e., $$$(x,y)$$$ must be distinct.
Note that each Bricked Blast Furnace must have a complete structure, but other blocks do not necessarily need to belong to a complete structure.
1
9 1 1 F 1 2 B 1 3 F 2 1 F 2 2 L 2 3 F 3 1 F 3 2 F 3 3 F
And no one makes me close my eyes
$$$~\\$$$
Deep in the Arctic permafrost lies an obsidian monolith etched with glowing celestial runes. These symbols — said to hold the fabric of spacetime — shift positions during auroral storms. Ancient texts warn that if the runes ever freeze in a "disordered sequence," two must be swapped exactly once to restore cosmic balance. Any additional tampering would collapse reality into quantum limbo.
When Vistar discovers the monolith frozen as a sequence, its hum resonates with impending doom. The decoded notes reveal: "One swap averts the rupture. Two swaps lead to chaos."
Now, as the ground trembles, he must answer: Are the runes already ordered by fate's design? If not, do exactly two exist whose swap would align them?
More formally, given $$$n$$$ numbers, please determine:
The first line contains a single integer $$$n$$$ $$$(1\le n\le 1000)$$$ — the number of runes.
The second line contains an array $$$a$$$ of length $$$n$$$ $$$(1 \le a_i\le 10^9)$$$.
If the runes are already in or can be restored in ascending order, output "Sorted". Otherwise, output "Failed".
51 4 3 2 5
Sorted
44 4 2 1
Failed
Keine is a teacher in Touhou Eiyashou. One day she gives you a problem in her class:
Give you an array $$$a_i$$$, we define $$$s_i$$$ as the prefix sum of $$$a_i$$$ (In other words, $$$s_i=\sum^i_{j=1}a_j$$$). Assume that an array $$$a_i$$$ is $$$\textbf{good}$$$ if and only if each $$$s_i$$$ satisfies $$$s_i \ge 0$$$.
Now Keine will perform a cyclic placement operation for $$$n$$$ times: Place $$$a_1$$$ behind $$$a_n$$$, which means that $$$[a_1,a_2...a_{n-1},a_n]$$$ will change to $$$[a_2,a_3...a_n,a_1]$$$. Then Keine will ask you whether the array $$$a_i$$$ is $$$\textbf{good}$$$.
Please output the number of $$$\textbf{good}$$$ arrays.
The first line consists of a positive integer $$$n\ (1\le n\le 10^5)$$$.
The second line consists of n positive integers $$$a_i\ (-10^3\le a_i\le 10^3)$$$.
The number of $$$\textbf{good}$$$ arrays.
5 2 3 -4 1 -1
2
There are $$$5$$$ arrays that you need to check:
The first and the fourth arrays are $$$\textbf{good}$$$.
$$$~\\$$$
As we all know, Neuro-sama is the best OSU! player.
After defeating every challenger, Neuro-sama wants to play another game named USO!. The rules of USO! are as follows:
There is an array $$$a$$$ of length $$$n$$$, with indices starting from $$$0$$$. You need to fill the array with a permutation of integers from $$$0$$$ to $$$n-1$$$ (i.e., each number is used only once).
You are given a binary string $$$s$$$ of length $$$n$$$. The array $$$a$$$ must satisfy the following conditions for all indices $$$i\ (0 \le i \lt n)$$$:
Neuro-sama wants to play USO! with you. Please output any legal $$$a$$$ as soon as possible. If there is no legal combination, output $$$-1$$$.
The first line contains one integer $$$n\ (1 \le n \le 2\cdot 10^5)$$$ — the length of array $$$a$$$ and $$$s$$$.
The second line contains one binary string $$$s$$$.
Print array $$$a$$$ if a legal $$$a$$$ exists. Otherwise, output $$$-1$$$.
10 1000010000
9 0 2 4 6 8 1 3 5 7
3 111
-1
$$$~\\$$$
Vistar finds himself trapped in a mysterious maze consisting of $$$n$$$ rooms. Surprisingly, the maze has no traditional doors — Instead, the $$$i-$$$th room contains $$$a_i$$$ portals.
Each portal is uniquely paired with exactly one other portal in the maze, forming a bidirectional connection. When Vistar enters a portal, he is instantly transported to the room of its paired portal. In particular, the portal may be paired to another portal within the same room.
Vistar begins his journey in room $$$1$$$ and aims to reach room $$$n$$$. However, the specific pairings of the portals are unknown. Your task is to determine whether Vistar can always reach the exit, regardless of how the portals are paired.
The first line contains a single integer $$$T$$$ $$$(1\le T \le 10^5)$$$ — the number of test cases. For each test case:
The first line of input contains one integer $$$n$$$ $$$(1 \le n\le 10^5)$$$. The second line contains an array $$$a$$$ of length $$$n$$$ $$$(1 \le a_i\le 10^9, \sum_{i=1}^{n}a_i$$$ is even$$$)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output "Yes" if Vistar can always reach room $$$n$$$ or "No" if not.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", and "YES" will be recognized as a positive response).
332 2 241 2 2 153 2 1 4 4
No Yes No
It was boilin', I run to the sea
It was boilin', I run to the sea
It was boilin', all on that day
$$$~\\$$$
Once again, Vistar finds himself trapped in a mysterious maze consisting of $$$n$$$ rooms. Surprisingly, the maze has no traditional doors — Instead, the $$$i-$$$th room contains $$$a_i$$$ portals.
Each portal is uniquely paired with exactly one other portal in the maze, forming a bidirectional connection. When Vistar enters a portal, he is instantly transported to the room of its paired portal. In particular, the portal cannot be paired to another portal within the same room.
Vistar begins his journey in room $$$1$$$ and aims to reach room $$$n$$$. However, the specific pairings of the portals are unknown. Your task is to determine whether Vistar can always reach the exit, regardless of how the portals are paired.
The first line contains a single integer $$$T$$$ $$$(1\le T \le 5\cdot 10^4)$$$ — the number of test cases. For each test case:
The first line of input contains one integer $$$n$$$ $$$(2 \le n\le 10^5)$$$. The second line contains an array $$$a$$$ of length $$$n$$$ $$$(1 \le a_i\le 5000, \sum_{i=1}^{n}a_i$$$ is even$$$)$$$.
It is guaranteed that:
For each test case, output "Yes" if Vistar can always reach room $$$n$$$ or "No" if not.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", and "YES" will be recognized as a positive response).
332 2 241 2 2 153 2 1 4 4
Yes Yes No
For sample $$$3$$$, a possible pairing is shown below:
It can be proven that for samples $$$1$$$ and $$$2$$$, Vistar can always reach room $$$n$$$ regardless of how the portals are paired.
Hakurei Reimu is good at playing maimai DX.
In maimai DX, there are $$$8$$$ touch-sensitive buttons arranged in a circular layout around the screen. We number them from $$$1$$$ to $$$8$$$ (picture 1).
picture 1 One day, Reimu is studying simai language. We always use simai language to describe a slide. A slide contains three parts: starting point, ending point, and sliding path.
There are 4 kinds of slides in maimai DX:
For example, there are $$$4$$$ slides in picture 6: $$$1 \gt 3,3\lor 5,1 \lt 7,7\lor 5$$$.
picture 6 Now we assume the radius of the maimai DX circle is $$$50$$$cm. Given a slide $$$x?y$$$, can you tell me the length of the slide?
The first line consists of a positive integer $$$T\ (1\le T\le 10^5)$$$.
The next $$$T$$$ lines, each line contains $$$x?y\ (1\le x,y\le 8,\ x \neq y,\ ?\in\{-$$$, >, <, v$$$\})$$$.
Please note that we use the lowercase letter "v" instead of "$$$\lor$$$" in our input.
$$$T$$$ lines, each line outputs the length of the slide.
The absolute or relative error within $$$10^{-6}$$$ is considered correct: Assuming the correct answer is $$$a$$$, your answer is $$$b$$$. It will be considered correct as long as $$$\frac{| a-b |}{max (a, 1)}\le 10^{-6}$$$.
4 1-4 2>5 3<6 1v3
92.3879532511 117.8097245096 196.3495408494 100.0000000000
Here are picture 2, picture 3, picture 4, and picture 5 from left to right:
![]() | ![]() | ![]() | ![]() |
The damage is done
The damage is done
$$$~\\$$$
Three times Vistar dreamed of the marvellous jewel, and three times was he snatched away while still he paused on the high terrace above it.
Each vision just ending the same way... In dreaming, Vistar had spent months planning the ultimate theft — to steal the Legendary Jewel of Mathematical Truth, a gem said to grant its wielder infinite knowledge.
The jewel was kept atop the Crown of Proofs, guarded by the relentless Math Police, an elite order devoted to protecting the foundations of mathematics. Their stronghold is The Tree of Mathematics, a rooted tree with $$$n$$$ nodes, where every branch represented a different field — number theory, graph theory, topology, and beyond.
On the grand night, Vistar infiltrated the root (node $$$1$$$). But as he reached for the jewel, an alarm echoed through the tree. Immediately, he found himself surrounded by the guards — At every leaf of this tree stood a Math Police officer, armed with Group Theory Rifles and Algebra Theory Snipers, determined to stop him from stealing the jewel atop the Crown of Proofs.
The scene was so vivid and clear:
Waking in a cold sweat, Vistar couldn't shake the question: Under such a siege, was escape even possible? We define escape as possible if Vistar isn't captured after $$$n$$$ turns.
Since he is in a panic, he wants you to answer the question.
The first line contains the number of test cases $$$T$$$ $$$(1\le T\le 1000)$$$ — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ $$$(2\le n\le 2000)$$$.
Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ $$$(1\le u,v\le n, u\neq v)$$$, denoting the two vertices connected by an edge. It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.
For each test case, output $$$n$$$ numbers $$$p_1, p_2, \dots, p_n$$$ representing the position of Vistar for the first $$$n$$$ moments if he can escape. Otherwise, output $$$-1$$$. If there exist multiple answers, output any of them.
2101 21 33 44 55 66 77 83 99 1055 14 13 12 1
1 3 4 4 3 9 10 10 10 10 -1
A possible escape route for the first test case is shown below:
In the study of probability theory and stochastic processes, the Random Descent Process (RDP) is an important class of mathematical models. In this context, we examine the following problem:
Given a positive integer $$$n$$$. You start with an integer $$$m$$$, whose initial value is $$$n$$$. In each operation, you replace $$$m$$$ with a uniformly random integer between $$$0$$$ and $$$m-1$$$ (inclusive) until $$$m$$$ becomes $$$0$$$. What is the expected number of operations required?
The first line of the input contains an integer $$$T$$$ ($$$1\le T \le 10^5$$$), representing the number of test cases.
For each test case, there is a single line containing a single integer $$$n$$$ ($$$0\le n \le 10^5$$$).
The output contains $$$T$$$ lines, one line for each test case, representing the expected number of operations required.
The absolute or relative error within $$$10^{-4}$$$ is considered correct: assuming the correct answer is $$$a$$$, your answer is $$$b$$$. It will be considered correct as long as $$$\frac{| a-b |}{max (a, 1)}\le 10^{-4}$$$.
501210100000
0.000000000000000 1.000000000000000 1.500000000000000 2.928968253968254 12.090146129863335
$$$~\\$$$
Be there, or be squared! In the vast, shimmering expanse of the digital stream, where data flows like rivers of light, Neuro-sama and her mischievous sister, Evil, are locked in a high-stakes game of hide-and-seek. The stream is a labyrinth of $$$n$$$ nodes, each glowing with a unique identifier from $$$1$$$ to $$$n$$$, pulsing with electric pathways.
For any node $$$u$$$, the digital pathways twist and turn under the following rules:
Evil has hidden herself, leaving only $$$q$$$ suspicious locations. Now, Neuro wonders: for each possible hiding spot $$$x$$$, how many nodes in the network (from $$$1$$$ to $$$n$$$) can reach it?
Since the number may be large, she wants to output it modulo $$$998244353$$$.
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.
The first line of each test contains two integers $$$n, q$$$ $$$(1\le n\le 10^{12}, 1\le q \le 10^6)$$$.
Each of the next $$$q$$$ lines contains one integer $$$x$$$ $$$(1\le x \le n)$$$.
It is guaranteed that the sum of $$$n$$$ in the test cases does not exceed $$$10^{12}$$$, and the sum of $$$q$$$ does not exceed $$$10^6$$$.
For each query of each test case, output the number of points connected to $$$x$$$ modulo $$$998244353$$$ on a separate line.
21219 512345325 391021
1 182 363 181 270 108 22 85
@atari_desu The casual game of hide-and-seek from the past has now escalated into a storm within the digital stream.
In their last game, Neuro-sama, with her exceptional computational abilities, could always swiftly pinpoint her sister Evil's hiding spots. However, being found so easily time and again ignited a flame of defiance in Evil's heart.
The once shimmering labyrinth of $$$n$$$ nodes has, under Evil's influence, expanded and contorted dramatically, becoming a vast and far more intricate "data cosmos." The rules of connection between nodes remain thesame, like the immutable physical laws of this universe.
For any node $$$u$$$:
Facing a digital cosmos of unprecedented scale and peril, Neuro-sama understands that tracing every possible path for each suspicious location is no longer feasible. She needs to rapidly calculate: for each possible hiding spot $$$x$$$, how many nodes in the network (from $$$1$$$ to $$$n$$$) can reach it.
Since the number may be large, she wants to output it modulo $$$998244353$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ $$$(1\le T \le 10^5)$$$. The description of the test cases follows.
The first line of each test contains two integers $$$n, q$$$ $$$(1\le n\le 10^{18}, 1\le q \le 10^6)$$$.
Each of the next $$$q$$$ lines contains one integer $$$x$$$ $$$(1\le x \le n)$$$.
It is guaranteed that the sum of $$$q$$$ does not exceed $$$10^6$$$. Note that there's no guarantee on the sum of $$$n$$$.
For each query of each test case, output the number of points connected to $$$x$$$ modulo $$$998244353$$$ on a separate line.
31219 512345325 3910211000000000000000000 2998244353998244354
1 182 363 181 270 108 22 85 159517010 638207148