Little A has a rectangular box with a height of $$$h$$$. He places this box on a table and establishes a three-dimensional Cartesian coordinate system $$$O-xyz$$$, where the table is located at $$$z=z_0$$$.
Due to Little A's obsessive-compulsive disorder, he places the length and width of the box parallel to the $$$x$$$ and $$$y$$$ axes (the length does not necessarily correspond to the $$$x$$$ axis), and the bottom face has a pair of diagonal vertices located at $$$(u_0,v_0,z_0)$$$ and $$$(u_1,v_1,z_0)$$$.
Now Little A has $$$q$$$ queries. For each query, he provides a point $$$(x_i,y_i,z_i)$$$ and wants to know if the point is inside the box (the boundary is also considered inside).
The first line contains six integers $$$z_0,h,u_0,v_0,u_1,v_1$$$ ($$$0\leq z_0,h\leq 10^6$$$, $$$-10^6\leq u_0,v_0,u_1,v_1\leq 10^6$$$).
The second line contains an integer $$$q$$$ ($$$1\leq q\leq 10^3$$$) indicating the number of queries.
The next $$$q$$$ lines each contain three integers $$$x_i,y_i,z_i$$$ ($$$-10^6\leq x_i,y_i,z_i\leq 10^6$$$) representing the $$$i$$$-th query.
Output $$$q$$$ lines. In the $$$i$$$-th line, output a string YES or NO. YES indicates that the queried point is inside the box, while NO indicates that it is not inside the box. The case does not matter, meaning you can output YES, Yes, YeS, yEs and NO, No, nO, etc.
1 1 -1 -1 1 13-1 -1 10 0 21 2 2
YES YES NO
Little A has many strings, each with a character set of $$$\{1,2,\cdots,m\}$$$. He constructed a Trie for these strings and built an Aho-Corasick automaton from this Trie.
However, due to Little A's negligence, both the original strings and the constructed Aho-Corasick automaton have disappeared. Little A only remembers that the lengths of all original strings do not exceed $$$d$$$, and that the constructed Aho-Corasick automaton has $$$n$$$ vertices and a character set of $$$\{1,2,\cdots,m\}$$$.
Now, Little A wants to know how many different Aho-Corasick automatons could possibly be the one he constructed. Since the answer can be large, you only need to find the result modulo $$$998244353$$$.
The Aho-Corasick automaton is defined as follows:
Two Aho-Corasick automatons are considered the same if and only if they have the same number of vertices and there exist two labeling schemes for the vertices (let's assume they are two permutations of length equal to the number of vertices) such that:
A single line containing three integers $$$n,m,d$$$ ($$$1\leq n,m,d\leq 100$$$), representing the number of vertices in the Aho-Corasick automaton, the size of the character set, and the upper limit on the lengths of all strings.
A single line containing an integer representing the answer.
3 2 2
5
Given a string $$$S$$$ composed of uppercase letters, please rearrange the order of the characters in $$$S$$$ such that the substring CCPC appears as many times as possible as a contiguous substring. You are to determine the maximum possible number of occurrences of CCPC.
A single line containing a string $$$S$$$ composed of uppercase letters $$$(1 \leq |S| \leq 10^6)$$$.
Output a single integer, representing the maximum possible number of occurrences of CCPC.
ABCDCPCPC
1
Little H has a permutation $$$P$$$, and he wants to split $$$P$$$ into sequence $$$A$$$ and sequence $$$B$$$.
Specifically, Little H will take several elements from $$$P$$$ in order and place them into sequence $$$A$$$, while the remaining elements will form another sequence $$$B$$$ in order.
For example, if $$$P = [1,2,3,4,5]$$$, he can split $$$P$$$ into $$$A = [1,3,5], B = [2,4]$$$.
He is very fond of increasing subsequences and decreasing subsequences. Define $$$f(A)$$$ as the length of the longest increasing subsequence of $$$A$$$, and $$$g(B)$$$ as the length of the longest decreasing subsequence of $$$B$$$. You need to tell him the maximum value of $$$f(A) + g(B)$$$.
The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 2\cdot 10^5)$$$, indicating the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \times 10^5)$$$, representing the length of the permutation $$$P$$$.
The second line contains $$$n$$$ integers $$$P_1,P_2,\ldots ,P_n$$$ $$$(1\leq P_i \leq n)$$$, ensuring that $$$P_i$$$ is a permutation.
The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output a single line containing an integer, representing the maximum value of $$$f(A) + g(B)$$$.
353 5 1 4 241 2 4 353 5 2 1 4
4 4 5
Given a rooted tree with $$$n$$$ nodes, rooted at $$$1$$$, which satisfies the property $$$p_i \lt i$$$, where $$$p_i$$$ is the parent node of $$$i$$$.
For each node $$$u$$$, for all its children $$$v$$$, we will provide the index of the centroid of the new tree formed by only considering $$$v$$$ and the nodes in the subtree of $$$v$$$, noting that we will not give you the index of $$$v$$$. If a tree has two centroids, we will tell you the one that is deeper in the original tree. Your task is to construct a tree that satisfies the above conditions.
The centroid of a tree: If a certain node is chosen and removed from the tree, the tree will be divided into several subtrees. The number of nodes in each subtree is counted, and the maximum value is recorded. The node for which this maximum value is minimized when considering all nodes in the tree is called the centroid of the entire tree.
The first line contains an integer $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, representing the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2\leq n \leq 2\cdot 10^5)$$$, representing the number of nodes in the tree.
The next $$$n$$$ lines provide first an integer $$$c_i$$$ $$$(1\leq c_i\leq n)$$$, representing the number of children of node $$$i$$$, followed by $$$c_i$$$ integers $$$p_{i,j}$$$ $$$(1\leq p_{i,j}\leq n)$$$, representing the index of the centroid of the tree formed by the $$$j$$$-th child of $$$i$$$ and the nodes in its subtree.
The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output $$$n-1$$$ lines. The $$$i$$$-th line should output two integers $$$u,v$$$ $$$(1\leq u,v \leq n, u\neq v)$$$, representing an edge $$$(u,v)$$$ in the tree.
The test data guarantees a solution. If there are multiple valid solutions, any one of them is acceptable.
242 3 41 30031 31 30
2 3 1 2 1 4 2 3 1 2
Little A has a sequence of positive integers of length $$$n$$$, denoted as $$$a_1, a_2, \cdots, a_n$$$. He wishes to create another sequence of positive integers of length $$$n$$$, denoted as $$$d_1, d_2, \cdots, d_n$$$, such that $$$d_i$$$ is a divisor of $$$a_i$$$.
It is evident that $$$d_1, d_2, \cdots, d_n$$$ are not unique, so Little A hopes that the product of $$$d_1, d_2, \cdots, d_n$$$ is a perfect square $$$x = y^2$$$, where $$$y$$$ is a positive integer.
However, at this point, $$$d_1, d_2, \cdots, d_n$$$ are still not unique. Therefore, Little A wants to know the sum of $$$y$$$, the square root of the product for all possible combinations of $$$d_1, d_2, \cdots, d_n$$$ that yield a perfect square $$$x = y^2$$$, modulo $$$10^9 + 7$$$.
The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) representing the length of the positive integer sequence.
The second line contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$), representing the positive integer sequence.
Output a single line containing an integer representing the answer.
24 4
11
Possible cases include $$$1 \times 1 = 1, 1 \times 2 = 2, 1 \times 4 = 4, 2 \times 1 = 2, 2 \times 2 = 4, 2 \times 4 = 8, 4 \times 1 = 4, 4 \times 2 = 8, 4 \times 4 = 16$$$.
Among these, the products that are perfect squares are $$$1 \times 1 = 1, 1 \times 4 = 4, 2 \times 2 = 4, 4 \times 1 = 4, 4 \times 4 = 16$$$.
The answer is equal to $$$\sqrt{1} + \sqrt{4} + \sqrt{4} + \sqrt{4} + \sqrt{16} = 1 + 2 + 2 + 2 + 4 = 11$$$.
Given a non-negative integer sequence $$$a$$$ of length $$$n$$$ and a constant value $$$k$$$.
Determine how many integers $$$x$$$ satisfy $$$x \in [0,k]$$$, such that $$$a_1 \oplus x, a_2 \oplus x, \ldots, a_n \oplus x$$$ forms a non-decreasing sequence.
Here, $$$\oplus$$$ denotes the XOR operation.
The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 2\cdot 10^5)$$$, indicating the number of test cases.
For each test case, the first line contains two integers $$$n,k$$$ $$$(1 \leq n \leq 2\cdot 10^5, 0 \leq k \leq 10^{18})$$$.
The second line contains $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \leq a_i \leq 10^{18})$$$.
The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output a single line containing an integer representing the count of integers $$$x$$$ that satisfy the conditions.
14 173 2 5 16
4
Little A has a string that only contains the characters 0 and 1 (hereafter referred to as a 01 string). He likes 1 and dislikes 0, so in Little A's eyes, there are only 1s in a 01 string.
Specifically, for a 01 string, Little A sees 0 as a separator that divides the string into several substrings consisting entirely of 1s. For example, for a 01 string 010011101111101, Little A sees four substrings that consist only of 1s: 1, 111, 11111, and 1.
For a 01 string, Little A defines its charm value as the sum of the square roots of the lengths of the separated substrings that consist entirely of 1s. For example, for the string 010011101111101, Little A's charm value is $$$\sqrt{1}+\sqrt{3}+\sqrt{5}+\sqrt{1}=2+\sqrt{3}+\sqrt{5}$$$.
Now, given a 01 string $$$s$$$, Little A hopes you can change some of the 1s in $$$s$$$ to 0s (or leave them unchanged) to maximize the charm value of this 01 string.
A single line containing a string $$$s$$$ that consists only of the characters 0 and 1 ($$$1\leq |s|\leq 10^6$$$).
A single line containing a floating-point number that represents the maximum charm value that can be obtained after the changes. Your answer is considered correct if the relative or absolute error compared to the standard answer does not exceed $$$10^{-9}$$$.
Assuming your answer is $$$a$$$ and the standard answer is $$$b$$$, it is considered correct if $$$\frac{|a-b|}{\max\{b,1\}}\leq 10^{-9}$$$.
1100110111
4.8284271247
Changing the 9th 1 to 0 will yield the maximum charm value of $$$2+2\sqrt{2}$$$.
Little H initially has a string $$$s$$$ composed of lowercase letters.
The charm value of a string is defined as the number of essentially different substrings.
For example, $$$\texttt{aaa}$$$ has only $$$3$$$ essentially different substrings: $$$\texttt{a}, \texttt{aa}, \texttt{aaa}$$$, while $$$\texttt{aabb}$$$ has $$$8$$$ essentially different substrings: $$$\texttt{a}, \texttt{aa}, \texttt{b}, \texttt{bb}, \texttt{ab}, \texttt{aab}, \texttt{abb}, \texttt{aabb}$$$.
He thinks the charm value of the initial string $$$s$$$ is too low, so he duplicates $$$s$$$ $$$m$$$ times and concatenates them together, trying to obtain a string with a higher charm value.
However, after he finished duplicating, he found that he could not accurately calculate its charm value. Please help him calculate the charm value of the duplicated string. Since the answer may be large, you need to output the charm value modulo $$$998244353$$$.
The first line contains two integers $$$n,m$$$ $$$(1 \leq n \leq 3 \times 10^5, 1 \leq m \leq 10^9)$$$, representing the length of the string $$$s$$$ and the number of duplications.
The second line contains a string $$$s$$$ composed of lowercase letters.
Output a single integer, representing the result of the charm value modulo $$$998244353$$$.
6 2mantle
57
12 1919810ifamjlifamjl
138226305
13 935330878aabbbbababbaa
348310505
Little H has two permutations $$$a$$$ and $$$b$$$, both of length $$$n$$$.
There are $$$q$$$ queries, and for each query, he will give you an interval $$$[l,r]$$$ for $$$a$$$ and an interval $$$[L, R]$$$ for $$$b$$$. He wants to know the value of $$$\sum\limits_{i=l}^r \sum\limits_{j=L}^R \gcd^2(a_i,b_j)$$$, but you only need to provide the result modulo $$$2^{32}$$$.
The first line contains a number $$$n$$$ $$$(1\leq n \leq 10^5)$$$, representing the length of $$$a$$$ and $$$b$$$.
The next line contains $$$n$$$ integers, representing the permutation $$$a$$$ $$$(1 \leq a_i \leq n)$$$, ensuring that $$$a_i \neq a_j$$$ for $$$i \neq j$$$.
The following line contains $$$n$$$ integers, representing the permutation $$$b$$$ $$$(1 \leq b_i \leq n)$$$, ensuring that $$$b_i \neq b_j$$$ for $$$i \neq j$$$.
The next line contains a number $$$q$$$ $$$(1\leq q \leq 10^5)$$$, representing the number of queries.
The next $$$q$$$ lines each contain four numbers $$$l,r,L,R$$$ $$$(1 \leq l \leq r \leq n, 1 \leq L \leq R \leq n)$$$, representing the intervals for the $$$i$$$-th query.
Output $$$q$$$ lines, where the $$$i$$$-th line outputs an integer representing the answer to the $$$i$$$-th query.
54 1 5 3 21 2 3 4 553 3 2 33 4 2 43 4 3 45 5 1 11 1 2 2
2 14 12 1 4
In the legendary magical land, there is a mysterious school. Xiao Kai is a student at this school, and recently his class is evaluating for the Excellent Student Scholarship and the Provincial Government Scholarship.
First, for each class, the allocation of Excellent Student Scholarship slots is as follows: Suppose a class has $$$n$$$ students, then at most $$$\lfloor{0.15n}\rfloor$$$ students will receive the first prize scholarship, at most $$$\lfloor{0.25n}\rfloor$$$ students will receive the second prize scholarship, and at most $$$\lfloor{0.35n}\rfloor$$$ students will receive the third prize scholarship. (For example, in a class of 21 students, 3 students will receive the first prize scholarship, 5 students will receive the second prize scholarship, and 7 students will receive the third prize scholarship.)
Each student will have scores in three areas: academic performance, moral education, and physical education, with scores being integers in the range $$$[0,100]$$$. The comprehensive score is the sum of the three scores. When evaluating scholarships, students will first be sorted in descending order by their comprehensive scores. If two students have the same comprehensive score, they will be sorted by their academic performance scores in descending order. If both comprehensive and academic scores are the same, they will be sorted by their names in ascending lexicographical order. The resulting ranking is referred to as the comprehensive ranking. The college will determine the order of scholarship applications based on the comprehensive ranking.
In addition, there is a rule that restricts the level of scholarship that students can apply for: students receiving the first prize scholarship must ensure that their academic performance score is in the top $$$25\%$$$ of the class, students receiving the second prize scholarship must ensure that their academic performance score is in the top $$$45\%$$$, and students receiving the third prize scholarship must ensure that their academic performance score is in the top $$$75\%$$$. (For example, in a class of 21 students, only the top 5 students in academic performance are eligible to receive the first prize scholarship, the top 9 students are eligible for the second prize scholarship, and the top 15 students are eligible for the third prize scholarship. Specially, if two students are tied for fifth place in academic performance, both are eligible to receive the first prize scholarship.)
After the Excellent Student Scholarships for the two semesters are awarded, the college will also evaluate the Provincial Government Scholarship. The college stipulates that there are only $$$m$$$ slots for the Provincial Government Scholarship in Xiao Kai's class. The evaluation method is to first sort by award points (where one first prize scholarship counts as 15 points, one second prize scholarship counts as 10 points, and one third prize scholarship counts as 5 points; for example, if student X receives one first prize scholarship and one second prize scholarship, their award points will be 25 points), then if the award points are the same, sort by the total comprehensive score in descending order, if the total comprehensive scores are the same, sort by the total academic performance score from both semesters in descending order, and if both total comprehensive scores and total academic performance scores are the same, sort by names in ascending lexicographical order.
Unfortunately, Xiao Kai was unable to win the Provincial Government Scholarship, which made him feel down. That night, he had a dream where he met an immortal sitting on a gourd, who could help him fulfill his wish of winning the Provincial Government Scholarship in his dream. The immortal can sell Xiao Kai several cups of drinks, where the first type of drink costs $$$p$$$ gold coins and can increase Xiao Kai's academic performance score in the first semester by 1 point, and the second type of drink costs $$$q$$$ gold coins and can increase Xiao Kai's academic performance score in the second semester by 1 point. (Note that each semester's academic performance score has a maximum limit of 100 points.)
Given that Xiao Kai's name is registered as crazyzhk, he now tells you all the scores of his class for the two semesters, and he wants to ask you how many gold coins he needs at a minimum to drink the purchased beverages and be able to win the Provincial Government Scholarship. If Xiao Kai cannot win the Provincial Government Scholarship no matter what, please output "Surely next time" (without quotes) to encourage him.
What is lexicographical order:
In simple terms, lexicographical order means "the order in which words appear in a dictionary." More accurately, the algorithm to determine the order of two different strings $$$S$$$ and $$$T$$$ composed of lowercase letters is as follows:
Let the $$$i$$$-th character of $$$S$$$ be denoted as $$$S_i$$$.
Define that if $$$S$$$ is lexicographically less than $$$T$$$, we consider $$$S \lt T$$$, and if $$$S$$$ is lexicographically greater than $$$T$$$, we consider $$$S \gt T$$$.
The first line contains an integer $$$n$$$ $$$(6 \leq n \leq 500)$$$, representing the number of students in Xiao Kai's class.
The next $$$n$$$ lines each consist of a string $$$name_i$$$ (composed only of lowercase letters) and six integers $$$a_{i,1},a_{i,2},a_{i,3},b_{i,1},b_{i,2},b_{i,3}$$$ $$$(0\leq a_{i,j},b_{i,j} \leq 100)$$$, representing the name of the $$$i$$$-th student, their academic performance score, moral education score, physical education score in the first semester, and their academic performance score, moral education score, physical education score in the second semester. It is guaranteed that each person's name is unique, and Xiao Kai's name is crazyzhk.
The next line contains three integers $$$m,p,q$$$ $$$(0 \le m \leq n,0 \leq p,q \leq 100)$$$, representing the number of slots for the Provincial Government Scholarship in Xiao Kai's class, the price of the first type of drink, and the price of the second type of drink.
Output a single integer representing the minimum number of gold coins Xiao Kai needs. If Xiao Kai cannot win the Provincial Government Scholarship under any circumstances, output the string "Surely next time" (without quotes).
8easycxk 94 12 77 74 70 55hardzhk 80 80 95 96 20 60crazyzhk 40 49 36 50 50 74mike 50 98 93 36 90 23amy 50 81 59 53 100 50tom 50 71 69 53 90 60john 65 73 41 60 34 69jyy 12 26 29 29 53 502 44 14
1494
7a 30 61 27 94 20 70b 64 57 68 8 43 34c 97 66 94 33 79 42crazyzhk 59 6 29 55 43 53e 65 78 61 71 31 2f 62 25 95 60 52 44g 60 90 30 62 42 542 72 22
858
8amy 94 12 77 100 70 55hardzhk 90 80 95 96 20 60john 90 39 16 70 50 74mike 100 98 93 90 90 23easycxk 70 81 59 73 100 50ydzlhzs 100 85 89 100 90 60crazyzhk 65 13 11 60 14 19jyy 92 26 29 69 53 802 44 14
Surely next time
In the first test case, the optimal solution is to buy 26 cups of the first type of drink and 25 cups of the second type of drink. After drinking, Xiao Kai's academic performance score in the first semester becomes 66 points, and in the second semester, it becomes 75 points.
The comprehensive ranking and scholarship situation for the first semester is as follows:
| Comprehensive Ranking | Name | Academic Score | Moral Score | Physical Score | Comprehensive Score | Scholarship Level | Academic Ranking |
| 1 | hardzhk | 80 | 80 | 95 | 255 | 1 | 2 |
| 2 | mike | 50 | 98 | 93 | 241 | 3 | 5 |
| 3 | amy | 50 | 81 | 59 | 190 | 3 | 5 |
| 4 | tom | 50 | 71 | 69 | 190 | 5 | |
| 5 | easycxk | 94 | 12 | 77 | 183 | 2 | 1 |
| 6 | john | 65 | 73 | 41 | 179 | 4 | |
| 7 | crazyzhk | 66 | 49 | 36 | 151 | 2 | 3 |
| 8 | jyy | 12 | 26 | 29 | 67 | 8 |
The comprehensive ranking and scholarship situation for the second semester is as follows:
| Comprehensive Ranking | Name | Academic Score | Moral Score | Physical Score | Comprehensive Score | Scholarship Level | Academic Ranking |
| 1 | amy | 53 | 100 | 50 | 203 | 3 | 5 |
| 2 | tom | 53 | 90 | 60 | 203 | 3 | 5 |
| 3 | crazyzhk | 75 | 50 | 74 | 199 | 1 | 2 |
| 4 | easycxk | 74 | 70 | 55 | 199 | 2 | 3 |
| 5 | hardzhk | 96 | 20 | 60 | 176 | 2 | 1 |
| 6 | john | 60 | 34 | 69 | 163 | 4 | |
| 7 | mike | 36 | 90 | 23 | 149 | 7 | |
| 8 | jyy | 29 | 53 | 50 | 132 | 8 |
The ranking for the Provincial Government Scholarship is as follows:
| Ranking | Name | Award Points | Total Comprehensive Score | Total Academic Score |
| 1 | hardzhk | 25 | 431 | 176 |
| 2 | crazyzhk | 25 | 350 | 141 |
| 3 | easycxk | 20 | 382 | 168 |
| 4 | amy | 10 | 393 | 103 |
| 5 | tom | 5 | 393 | 103 |
| 6 | mike | 5 | 390 | 86 |
| 7 | john | 0 | 342 | 125 |
| 8 | jyy | 0 | 199 | 41 |
$$$2\times 2$$$ and $$$3\times 3$$$ rectangle examples, A, B, C, D represent four basic blocks Little Y wants to play a type of puzzle that consists of four basic blocks, as shown in the image above. Little Y has $$$A, B, C, D$$$ of these four types of blocks. Now he wants to use as many blocks as possible to form a rectangle (either a rectangle or a square). The question is, what is the maximum number of blocks he can use?
The formed rectangle must satisfy the following conditions:
The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, indicating the number of test cases.
For each test case, each line contains four integers $$$A, B, C, D$$$ $$$(0 \leq A, B, C, D \leq 10^3)$$$, representing the number of four types of basic blocks.
Output $$$n$$$ lines, each line containing an integer that indicates the maximum number of given blocks that can be used to form a rectangle. If it is not possible to form a rectangle, please output $$$0$$$.
24 0 0 04 4 4 4
4 16
Given a tree with $$$n$$$ nodes, you can use several line segments of arbitrary lengths to cover all the edges of the tree, with the following requirements:
You can choose any number of line segments such that these segments can cover the entire tree according to the above requirements, but you need to minimize the maximum length of the segments. Your task is to find this minimum value.
The first line contains an integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, representing the number of test cases.
For each test case, the first line contains an integer $$$n$$$ $$$(2 \le n \le 2\cdot 10^5)$$$, representing the total number of nodes in the tree.
The second line contains $$$n-1$$$ integers $$$p_2, p_3, \ldots , p_n$$$ $$$(1 \le p_i \lt i)$$$, where $$$p_i$$$ represents the index of the parent node of node $$$i$$$.
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 on a new line, representing the minimum possible maximum length of the line segments.
281 2 3 2 5 1 781 2 3 4 5 6 7
3 7
For the first sample test case, the illustration is as follows. The red, green, and blue segments represent three line segments with lengths of 2, 3, and 2, respectively.