Alice and Bob play a table tennis match under the 11-point system. Alice wins the match in the end. The rules for ending the match are as follows:
The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, representing the number of test cases. Then $$$T$$$ lines follow. Each line contains a positive integer $$$N$$$ $$$(11 \le N \le 10^9)$$$. It is guaranteed that $$$N$$$ is a valid final state of the match.
For each test case, output one line with the score in the format a:b. An example is 11:5.
6111420222430
11:0 11:3 11:9 12:10 13:11 16:14
You are given a rooted tree with $$$n$$$ nodes, where the root is node $$$1$$$. Each node of the tree is labeled with a lowercase English letter.
You need to count the number of valid 5-tuples of nodes $$$(u_1, u_2, u_3, u_4, u_5)$$$ that satisfy the following conditions. The answer should be computed modulo $$$998244353$$$.
The first line contains a single positive integer $$$n$$$ $$$(1 \leq n \leq 5 \times 10^5)$$$, denoting the number of nodes in the tree. The second line contains a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters, where $$$s_i$$$ denotes the letter on node $$$i$$$. The third line contains $$$n-1$$$ positive integers $$$fa_2, fa_3, \dots, fa_n$$$, where the $$$i$$$-th integer represents the parent of node $$$(i+1)$$$. It is guaranteed that $$$1 \leq fa_i \lt i$$$.
Print a single integer representing the number of valid 5-tuples modulo $$$998244353$$$.
5cbdae1 1 2 3
1
5cbdea1 1 2 3
0
8ccdbdeae1 1 2 2 3 4 5
2
9ccdbdfaee1 1 2 2 3 4 5 6
2
Long long ago, the universe existed as a high-dimensional space. Planets are neatly arranged here. Interstellar conflicts occur frequently, yet counterattacks are not allowed.
In an $$$n$$$-dimensional space, the coordinate of the $$$i$$$-th dimension is an integer within the range $$$[1, a_i]$$$. The set of all lattice points is defined as:
$$$$$$ \{(x_1, x_2, \dots, x_n) \mid 1 \le x_i \le a_i,\ x_i \in \mathbb{Z}\}. $$$$$$
Initially, all points satisfying $$$x_i \le b_i$$$ for every $$$i$$$ are colored black (every coordinate is no larger than the corresponding threshold $$$b_i$$$), and all other points are white.
Alice and Bob take turns to perform operations, and Alice moves first. In each turn, the current player must select a white point $$$P = (x_1, x_2, \dots, x_n)$$$. After the selection, all points $$$Q = (y_1, y_2, \dots, y_n)$$$ satisfying $$$y_i \ge x_i$$$ for every $$$i$$$ will be colored black. A player loses if they cannot choose any white point to operate on.
Both players adopt optimal strategies. For each test case, determine whether Alice has a winning strategy.
The first line contains an integer $$$T$$$ $$$(1 \le T \le 2\times 10^5)$$$, representing the number of test cases.
For each test case:
The first line contains an integer $$$n$$$ $$$(1\le n \le 2\times 10^5)$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$.
The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le a_i \le 10^9)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\times 10^5$$$.
For each test case, output one line. Print Yes if Alice has a winning strategy, otherwise print No. The answer is case-insensitive.
51105210 1010 1023 32 235 5 54 5 542022 1029 1430 1830100 100 45 100
Yes No Yes Yes Yes
In a future autonomous interception drill, commander Alice uses $$$n$$$ unmanned interceptors (denoted as $$$A_1, A_2, \ldots, A_n$$$) to surround an intruding target $$$B$$$ controlled by Bob. All units move on a two-dimensional plane. Whether the interception succeeds depends not only on the initial layout, but also on the path planning strategies of both participants.
You are given the initial coordinates $$$A_i(x_i, y_i)$$$ of the $$$n$$$ interceptors and the starting position $$$(x_0, y_0)$$$ of target $$$B$$$ on the 2D plane.
Game Rules:
There are $$$q$$$ independent queries. For each query, a new initial position $$$(x_0, y_0)$$$ of target $$$B$$$ is given. For every query, determine whether Alice is able to catch Bob under optimal play from both sides.
The first line contains two positive integers $$$n, q$$$ ($$$1 \le n,q \le 2 \times 10^5$$$).
The next $$$n$$$ lines each contain two integers $$$x_i, y_i$$$, representing the coordinates of $$$A_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$).
The next $$$q$$$ lines each contain two integers $$$x_0, y_0$$$, representing the initial position of target $$$B$$$ in the corresponding query.
Print $$$q$$$ lines in total. For each line, output either Yes or No. Print Yes if Alice can catch Bob, otherwise print No. The answer is case-insensitive.
5 50 06 00 61 00 11 00 12 01 1-1 0
YES YES NO YES NO
Then winter comes — the snow keeps falling and accumulating, eventually covering all sins. Finally spring arrives — along with the melting snow, all punishments are delivered.
Just cure whoever you can. There is no way to fix the problem setter who designed this problem.
As we all know, a person who is obsessed with bad endings just like this problem setter can never be cured. But if a problem can be solved with only slope optimization, it is still worth a try.
Given a sequence of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$. You need to perform $$$q$$$ operations in total, choosing from the two types below. It is guaranteed that every number in the sequence always stays within the range $$$[1, 2 \times 10^5]$$$.
The first line contains two positive integers $$$n, q$$$ $$$(2 \le n \le 2 \times 10^5, 1 \le q \le 2 \times 10^5)$$$.
The second line contains $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 2 \times 10^5)$$$.
The following $$$q$$$ lines describe the operations:
Each line starts with an integer $$$op \in \{1,2\}$$$. If $$$op = 1$$$, three positive integers $$$l, r, x$$$ follow $$$(1 \le l \le r \le n, 1 \le x \le 2 \times 10^5)$$$, which means adding $$$x$$$ to every element in interval $$$[l,r]$$$. If $$$op = 2$$$, two positive integers $$$l, r$$$ follow $$$(1 \le l \lt r \le n)$$$, which means querying the minimal total weight of interval $$$[l, r]$$$.
For each query of type $$$op=2$$$, output two integers $$$a$$$ and $$$b$$$ separated by a single space on one line. Constraints: $$$a \ge 0,\ b \gt 0,\ \gcd(a, b) = 1$$$. The minimal weight equals $$$\dfrac{a}{b}$$$. Specially, if the minimal weight is an integer $$$x$$$, you should output $$$x$$$ and $$$1$$$.
6 101 2 3 4 5 62 2 51 1 6 12 1 61 3 4 22 1 32 4 61 5 5 11 1 2 31 1 1 12 1 6
1 1 3 2 26 3 2 3 0 1
"Why did it come to this? I finally met someone I love, and also gained a lifelong best friend. Two kinds of joy blend together, and this double joy brings endless more happiness. I was supposed to embrace a dreamlike happy life. But why... why has everything turned out like this?"
Given a positive integer $$$n$$$, consider all positive integers in the interval $$$[n, n^2]$$$.
A positive integer $$$k$$$ is defined as good if it meets both of the following requirements:
For the given $$$n$$$, you are required to:
The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 5000)$$$, indicating the number of test cases. Each of the next $$$T$$$ lines contains a positive integer $$$n$$$ $$$(1 \le n \le 5000)$$$.
For each test case, output two lines. The first line contains a non-negative integer $$$c$$$, representing the number of good integers in $$$[n, n^2]$$$. The second line contains a positive integer $$$k \in [n, n^2]$$$ which is a good integer. If there are multiple answers, you may output any of them.
As a special case: if no good integer exists in $$$[n, n^2]$$$, output $$$0$$$ on the first line and $$$-1$$$ on the second line.
512345
1 1 1 3 2 5 2 11 4 13
If only I had held the hero's hand instead of the commemorative coin back then...
There are $$$n$$$ commemorative coins arranged in a row. Initially, all coins are facing up.
In one operation, you can choose a consecutive segment of exactly $$$k$$$ coins and flip all of them.
Given a final state $$$s$$$ describing whether each coin is heads up or tails up, determine if it is possible to reach this state from the initial state using any number of operations (including zero operations).
The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 2 \times 10^5)$$$, denoting the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ across all test cases in a single test set does not exceed $$$2 \times 10^5$$$.
For each test case, output a single line containing Yes if the state is reachable, otherwise output No. The answer is case-insensitive.
25 3011103 2100
YES NO
wzj has invented a brand new Ludo game! This game comes with a huge board and a giant die.
wzj really enjoys this game, but he can never gather enough players to start a match. Other people think one full game takes far too much time, so no one wants to play with him.
He wants to prove that the game can end quickly if everyone plays with the optimal strategy. Unfortunately, he does not know how to calculate the exact number of turns.
Could you help him solve this problem?
The board has $$$n$$$ cells numbered from $$$1$$$ to $$$n$$$. Initially, wzj's piece is placed on cell $$$1$$$. There is an $$$m$$$-sided die. Each roll generates an integer chosen uniformly at random from $$$1$$$ to $$$m$$$.
In each turn, wzj first rolls the die. Let the result be $$$x$$$. After seeing $$$x$$$, he has two choices: move forward by $$$x$$$ steps, or skip the turn and stay in place.
The goal is to reach cell $$$n$$$ as quickly as possible.
Under the optimal strategy (which minimizes the expected number of turns to reach cell $$$n$$$), calculate the expected number of turns needed for wzj to travel from cell $$$1$$$ to cell $$$n$$$.
One line contains two positive integers $$$n, m$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le m \lt n$$$), representing the total number of cells and the number of faces of the die.
Print a single real number, which is the expected number of turns under the optimal strategy. Your answer is considered correct if the absolute error or relative error between your output and the standard answer is no more than $$$10^{-6}$$$.
8 6
7.0000000000
4 2
3.0000000000
5 2
3.5000000000
100 6
33.0476190476
You are participating in a programming contest. There are $$$n$$$ problems in total. The $$$i$$$-th problem has the following attributes:
Formally, if you solve the $$$i$$$-th problem at time $$$s$$$ (timed from the start of the contest), the actual score you get from this problem is $$$a_i - b_i \cdot s$$$.
The total duration of the contest is $$$T$$$. You can solve any number of problems in any order (you may choose not to solve some problems), but the total time consumed by all solved problems must not exceed $$$T$$$.
You need to maximize the total score you obtain.
The first line contains two integers $$$n, T$$$ ($$$1 \le n \le 2000$$$, $$$1 \le T \le 2000$$$).
The next $$$n$$$ lines each contain three integers $$$a_i, b_i, t_i$$$ ($$$0 \le a_i, b_i \le 10^6$$$, $$$1 \le t_i \le T$$$).
Print a single integer on a line, representing the maximum possible total score.
3 1010 1 320 2 530 3 4
21
If you solve problem 3 first and then problem 1, your score will be $$$(30-4\times 3)+(10-(4+3)\times 1)=21$$$.
The ACM team of BNU is recruiting new members!
After multiple rounds of selection, all candidates have successfully joined the team, except wzj and xyz, whose final spots are still pending.
You decide to team up with them for an ACM contest to evaluate their coding skills. The three of you share one computer during the contest. The problems are fairly easy, so you solve all of them effortlessly and assign a score to each problem. Then you let wzj and xyz take turns to write code for the problems. wzj moves first, and xyz moves second. Both of them hope to win your recognition, so they try to maximize their own total scores to show their ability.
There are $$$n$$$ problems in total, and each problem belongs to one of the following two types:
wzj and xyz take turns to make moves, with wzj moving first. On each turn, the current player must select and complete one problem from all currently available problems, and gain the score of that problem.
Definition of available problems:
The game ends after all problems are completed.
Both players aim to maximize their own total score. Given that both of them adopt optimal strategies, please calculate the final scores of wzj and xyz.
The first line contains an integer $$$n$$$ $$$(1 \le n \le 2 \times 10^5)$$$, denoting the number of problems (each problem is either single-part or two-part).
The following $$$n$$$ lines each describe one problem:
Output two integers separated by a single space on one line, which are the total scores of wzj and xyz under optimal strategies.
32 1 1002 6 51 3
109 6
This in an interactive problem.
Note: This problem uses an adaptive interactor.
This problem was written on May 20th.
In this school contest, I committed three crimes.
The crime of adding $$$0$$$ to the data range, causing a division by zero error if the code does not handle it as a special case.
The crime of setting the upper bound of binary search to $$$10^{18} + 10^9$$$, and making intermediate variables reach the order of $$$10^{23}$$$, leading to an extremely error-prone upper bound and integer overflow in the code.
And... and there's more...
The felony of replacing the problem four days before the contest, creating a new problem, and intentionally writing a wrong interactor...
To test the support for interactors on the school contest platform, xyz tried to implement an adaptive interactor for the classic interactive template (binary number guessing). Unfortunately, he wrote the interactor incorrectly.
The description of the number guessing problem is as follows: The judge has a positive integer $$$x$$$ in the range $$$[1, 10^9]$$$. You need to guess the value of $$$x$$$ with no more than $$$100$$$ queries. For each query, you ask the judge for a positive integer $$$y$$$ in $$$[1, 10^9]$$$. The judge returns $$$1$$$ if $$$y \ge x$$$, and returns $$$0$$$ if $$$y \lt x$$$.
The logic of the wrong interactor designed by xyz is as follows: To maximize the number of subsequent queries required by the guessing program, the interactor should choose the response that results in a longer new interval. If the lengths are equal, either choice is acceptable (usually $$$0$$$ or $$$1$$$). In this way, after each response, the interval size is at least half of the original interval size (rounded up), making the number of queries approach the information-theoretic lower bound $$$\lceil \log_2 10^9 \rceil = 30$$$.
xyz believed that if the existing conditions only imply that $$$x$$$ lies in the interval $$$[l, r]$$$, the correct choice can be made by comparing $$$|y - l|$$$ and $$$|y - r|$$$. Thus, he implemented the following rules:
The way to determine $$$l$$$ and $$$r$$$ in xyz's wrong interactor is as follows:
According to the definition of the response, the true value $$$x$$$ must lie within the interval $$$[l, r]$$$, and this is the minimal possible interval derived from the existing responses.
For example, if it is currently only known that $$$x$$$ is in the interval $$$[5, 9]$$$ (i.e., $$$l=5, r=9$$$), when querying $$$y = 7$$$, xyz's wrong interactor compares $$$|7-5|=2$$$ and $$$|7-9|=2$$$. Since they are equal, it returns $$$1$$$ with a $$$50\%$$$ probability and $$$0$$$ with a $$$50\%$$$ probability. If it returns $$$1$$$, the new interval becomes $$$[5, 7]$$$; if it returns $$$0$$$, the new interval becomes $$$[8, 9]$$$. This wrong interactor has a $$$50\%$$$ chance to choose the longer interval, which affects subsequent interval updates.
Note: Since xyz's interactor is implemented incorrectly, $$$l \le r$$$ is NOT guaranteed during the interaction. The response is only determined by the relative values of $$$|y - l|$$$ and $$$|y - r|$$$.
Now, there are two types of interactors. The first is the correct interactor, which gives logically consistent results in all cases (it is an adaptive interactor, but its adaptation method may differ from any of those described in the problem statement). The second is xyz's wrong interactor, which interacts following the rules above. You can make no more than $$$100$$$ queries to the interactor to determine which type you are interacting with.
Note: The correct implementation of the adaptive interactor required to solve this problem is as follows:
Note: The interactor in this problem will not adapt its type. For each test case, the type of interactor is pre-determined before any queries are made.
This problem contains multiple test cases. The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 100)$$$, denoting the number of test cases.
For each test case, repeat the following steps:
You must flush the standard output buffer after every output operation, otherwise the interactor may not receive your output in time, resulting in a time limit exceeded or wrong answer.
Methods to flush the output in common programming languages are as follows:
2 1 0 0 0
? 400000000 ! correct ? 1000 ? 10000 ? 100000 ! wrong
There are two test cases in the sample.
For the first test case, the pre-determined $$$x \le 4 \times 10^8$$$. Querying $$$4 \times 10^8$$$ returns $$$1$$$, which is impossible for the wrong interactor, so we can directly judge that the interactor is correct.
For the second test case, the interactor is wrong, and the returned results match the pattern of the wrong interactor. Even if you guess without certainty, the answer will be accepted as long as the guess is correct.
You have an initial string $$$S$$$, and $$$q$$$ operations will be performed sequentially. There are three types of operations:
After all operations are completed, you need to answer: what is the $$$P$$$-th character of the final string? The indices start from $$$1$$$. It is guaranteed that $$$P$$$ does not exceed the length of the final string.
The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, denoting the number of test cases.
For each test case:
Guarantees: The sum of $$$|S|$$$ across all test cases does not exceed $$$2 \times 10^5$$$, and the sum of $$$q$$$ across all test cases does not exceed $$$2 \times 10^5$$$. For each test case, the length of the string after all operations is at least $$$P$$$.
For each test case, output a single character on a line, which is the $$$P$$$-th character of the final string.
1ab31 c32 14
a
Given a sequence of prime numbers $$$p_1, p_2, \dots, p_n$$$, where each $$$p_i$$$ is a prime number no greater than $$$10^7$$$.
Find two intervals $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$ that satisfy $$$1 \le l_1 \le r_1 \le n$$$, $$$1 \le l_2 \le r_2 \le n$$$ and $$$(l_1, r_1) \neq (l_2, r_2)$$$, such that the product of all elements inside the two intervals is equal:
$$$$$$ \prod_{i=l_1}^{r_1} p_i = \prod_{j=l_2}^{r_2} p_j $$$$$$
You may output any valid pair if multiple solutions exist. If no such pair of distinct intervals exists, output -1.
The first line contains a positive integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, denoting the number of test cases.
For each test case:
Guarantee: The sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case:
342 2 2 252 3 5 7 11717 2 5 17 5 5 2
1 3 2 4 -1 2 5 4 7
There are three test cases in the sample.
For the first test case, select $$$l_1 = 1, r_1 = 3, l_2 = 2, r_2 = 4$$$. We have $$$\prod_{i=l_1}^{r_1} p_i = \prod_{j=l_2}^{r_2} p_j = 8$$$.
For the second test case, it can be proven that there is no valid solution.
For the third test case, select $$$l_1 = 2, r_1 = 5, l_2 = 4, r_2 = 7$$$. We have $$$\prod_{i=l_1}^{r_1} p_i = \prod_{j=l_2}^{r_2} p_j = 850$$$.