Tyger has an array of positive integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ of length $$$n$$$, on which he wants to perform a series of operations. An operation on an array consists of removing a number $$$x$$$ from the array and adding two positive integers $$$y$$$ and $$$z$$$ to the array such that $$$x = y + z$$$ and the addition doesn't yield any carries. Find the maximum possible number of operations Tyger can perform on the array.
The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$, representing the length of the array.
The following line contains $$$n$$$ positive integers $$$a_1, a_2, \dots ,a_n$$$ $$$(1 \leq a_i \leq 10^{10^4})$$$, representing Tyger's original array.
Output a single integer, the maximum number of operations that can be done on array $$$a$$$.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$a_i \leq 9$$$ | $$$30$$$ |
| $$$2$$$ | $$$a_i \leq 10^9$$$ | $$$40$$$ |
| $$$3$$$ | No additional constraints | $$$30$$$ |
4 1 2 3 11
4
The first element, $$$1$$$, cannot be split any further using an operation. Tyger can complete an operation and split $$$2$$$ into $$$1$$$ and $$$1$$$, and since $$$1$$$ cannot be split any further, $$$2$$$ allows for one operation. $$$3$$$ can be split into $$$2$$$ and $$$1$$$, and since $$$2$$$ can be split once and $$$1$$$ can be split no more times, we can complete a total of two operations. $$$11$$$ can be split into $$$10$$$ and $$$1$$$, allowing for one operation.
Therefore, Tyger can complete a total of $$$1 + 2 + 1 = 4$$$ operations on this array.
Tyger is practicing on an archery target, which is an $$$n \times n$$$ grid of unit squares on the coordinate plane, where $$$n$$$ is odd. The target is arranged into concentric square rings around a single center square.
Each unit square is labeled by a pair of integers $$$(x, y)$$$. The target's bottom-left square is labeled $$$(x_0, y_0)$$$, and the square $$$i$$$ columns right and $$$j$$$ rows up $$$(0 \leq i, j \leq n - 1)$$$ is labeled $$$(x_0 + i, y_0 + j)$$$.
The outermost ring is worth $$$1$$$ point, and the score increases by $$$1$$$ for each ring toward the center. The single center square is worth $$$\frac{n + 1}{2}$$$ points. The squares outside of the target are worth $$$0$$$ points.
Tyger wants you to answer $$$q$$$ queries:
The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1 \leq n \leq 10^8, 1 \leq q \leq 2 \cdot 10^5)$$$, representing the size of the target and the number of arrows fired respectively.
The second line contains two integers $$$x_0$$$ and $$$y_0$$$ $$$(-10^8 \leq x_0, y_0 \leq 10^8)$$$, representing the label of the bottom-left unit square in the target.
The next $$$q$$$ lines represent the queries.
A query of type $$$1$$$ will have a line in the format 1 x y $$$(-10^8 \leq x, y \leq 10^8)$$$, where $$$(x, y)$$$ represents the position the arrow hits the plane.
A query of type $$$2$$$ will have a line in the format 2 p $$$(1 \leq p \leq \frac{n + 1}{2})$$$, where $$$p$$$ represents the number of points the arrow scored.
Output $$$q$$$ lines, where line $$$i$$$ contains the answer to query $$$i$$$.
5 3 1 1 1 3 3 2 3 2 1
3 6 96

For the first query, the arrow hits the center of the target, scoring $$$3$$$ points. For the second query, the only way an arrow could score $$$3$$$ points is if it hit the center unit square of the target, which has label $$$(3, 3)$$$, and $$$3 + 3 = 6$$$.
LexMACS needs your help! There have been rumors of an in-person LIT, causing a multitude of desks to be purchased. Their arrangement on an $$$n$$$ by $$$m$$$ tile floor, where each tile is either fully below a desk or empty, can be shown through a binary grid, where a $$$1$$$ denotes the presence of a desk and a $$$0$$$ denotes the absence of a desk. The floor has walls on its edges, meaning that both competitors and proctors cannot go off the floor.
However, preemptive measures against cheaters have been placed. The room's proctor will initially teleport to an empty tile, and move to other adjacent, empty tiles as much as they want. A proctor is able to check a competitor and their desk for cheating if they are able to stand directly adjacent to the desk.
Help the proctor determine if a certain location for initial teleportation is effective for stopping cheaters, that is, whether the proctor can check each desk!
The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 100)$$$, representing the number of test cases.
The first line of each test cases contains two integers $$$n$$$ and $$$m$$$ $$$(1 \leq n, m \leq 10^5)$$$, the number of rows and columns of tiles in the room respectively.
The next $$$n$$$ lines of the test case each contain a string of length $$$m$$$, where $$$1$$$ denotes the presence of a desk at that tile and $$$0$$$ denotes its absence. It is guaranteed that there would be at least one desk in the room.
The next line of the test case contains $$$q$$$ $$$(1 \leq q \leq 10^5)$$$, the number of teleportation locations you will be given.
Each of the next $$$q$$$ lines of the test case contain $$$r$$$ and $$$c$$$ $$$(1 \leq r \leq n, 1 \leq c \leq m)$$$, respectively the row and column where the proctor will initially teleport.
It is guaranteed that the both the sum of $$$nm$$$ and the sum of $$$q$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
In response to each initial teleportation location, output "YES" without quotes if teleporting to that location is effective for stopping cheaters and "NO" without quotes otherwise.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$n,m,q \leq 100,\;\sum nm \leq 5 \cdot 10^4,\;\sum q \leq 500$$$ | $$$20$$$ |
| $$$2$$$ | No additional constraints | $$$80$$$ |
16 610100100101000010011001000010000000121 54 4
NOYES
For the first location, the proctor will teleport to the tile in the first row and the fifth column. The grid can be seen below, where "X" denotes the location of the proctor after initially teleporting.
1010X1
001010
000100
110010
000100
000001
It can be shown that the proctor can move to the following locations below, denoted by an "X". The proctor is able to check the desks marked with a "C".
10CXXC
00CXC0
000C00
110010
000100
000001
Thus, the answer is "NO" for the first query, as the proctor is not able to check all desks, making their initial teleportation to that location ineffective for stopping cheaters.
For the second location, it can be shown that the proctor can check all desks, making their teleportation to the tile on the fourth row and the fourth column effective for stopping cheaters.
Cody wants to shoot a missile to hit Tyger. The missile starts at $$$(0, 0)$$$, and follows a parabolic trajectory under gravity, modeled by the equation $$$y = ax^2 + bx$$$, where $$$a \lt 0$$$ and the trajectory passes through the enemy's position $$$(E_x, E_y)$$$.
Between them, there are $$$n$$$ vertical obstacles. The $$$i$$$th obstacle is at x coordinate $$$x_i$$$ and spans a closed interval $$$[y_i, z_i]$$$. In other words, the obstacle can be seen as a segment connecting $$$(x_i, y_i)$$$ and $$$(x_i, z_i)$$$.
The missile moves continuously along the curve, but it can't pass through any obstacle.
Your task is to find a set of coefficients $$$(a, b)$$$ such that the missile hits Tyger and avoids all obstacles. If multiple such trajectories exist, output the one where $$$a$$$ is maximized. It is guaranteed that a solution exists.
The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 100)$$$, representing the number of test cases.
The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^4)$$$, the number of vertical obstacles.
The second line of each test case contains two integers $$$E_x, E_y$$$ $$$(0 \lt E_x \leq 10^5, -10^9 \leq E_y \leq 10^9)$$$, describing Tyger's position.
Each of the next $$$n$$$ lines contains integers $$$x_i$$$, $$$y_i$$$, and $$$z_i$$$ $$$(0 \lt x_i \lt E_x, -10^9 \leq y_i, z_i \leq 10^9)$$$, representing each obstacle.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$.
For each test case, on a single line, output $$$a$$$ and $$$b$$$, the coefficients for the parabolic trajectory of the missile.
Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$v$$$ and the jury's answer be $$$u$$$. Your answer is accepted if and only if $$$\frac{|v - u|}{\max(1, |u|)} \leq 10^{-6}$$$.
224 02 -4 41 -1 116 03 -3 5
-1 4 -0.555556 3.333333
In the first example, the optimal trajectory is $$$y = -x^2 + 4x$$$, where the missile grazes the top of the first obstacle. It can be proven that no larger $$$a$$$ is possible.
You are given a tree with $$$n$$$ vertices, labeled from $$$1$$$ to $$$n$$$. Each vertex $$$i$$$ has a hidden label $$$v_i$$$, and the array of hidden values $$$[v_1, v_2, \ldots, v_n]$$$ forms a permutation of integers from $$$1$$$ to $$$n$$$.
You are not given the hidden values directly. Instead, you are given the structure of the tree and the weights of its $$$n - 1$$$ edges. The weight of the edge connecting vertex $$$i$$$ and vertex $$$j$$$ is $$$v_i \oplus v_j$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.
Your task is to reconstruct the hidden labels $$$v_1, v_2, \dots v_n$$$ with the given information.
The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 100)$$$, representing the number of test cases.
The first line of each test case contains $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$, the number of vertices in the tree.
The next $$$n - 1$$$ lines of each test case each contain three integers $$$i$$$, $$$j$$$, and $$$v_i \oplus v_j$$$ and each represent an edge in the tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
On a single line, output the labels of vertices $$$1, 2, 3, \ldots, n$$$ in order.
If there are multiple solutions, you can output any of them.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$n$$$ is odd | $$$30$$$ |
| $$$2$$$ | $$$\sum n \leq 5000$$$ | $$$30$$$ |
| $$$3$$$ | No additional constraints | $$$90$$$ |
1 5 1 2 7 1 3 5 3 4 4 3 5 3
4 3 1 5 2
The labels satisfy the constraints because we have
A left circular shift of a sequence moves its first element to the end. For example, the sequence $$$[1, 2, 3, 4]$$$ becomes $$$[2, 3, 4, 1]$$$ after applying a circular shift.
We can construct a grid $$$g$$$ of size $$$n$$$ by $$$n$$$ as follows: The first row of $$$g$$$ is $$$[1, 2, ..., n]$$$. For $$$i = 2$$$ to $$$n$$$, row $$$i$$$ is obtained by applying a left circular shift to row $$$i - 1$$$.
For example, when $$$n = 4$$$ our grid is:
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
You need to process $$$q$$$ queries of the following four types:
R x k: Apply a left circular shift on row $$$x$$$ by $$$k$$$ positions if row $$$x$$$ is a circular shift of $$$[1, 2, ..., n]$$$.
C x k: Apply an upward circular shift on column $$$x$$$ by $$$k$$$ positions if column $$$x$$$ is a circular shift of $$$[1, 2, ..., n]$$$.
S x y: Swap rows $$$x$$$ and $$$y$$$
Q x y: Output the value currently in row $$$x$$$, column $$$y$$$
The first line contains two integers $$$n$$$ and $$$q$$$, $$$(1 \leq n, q \leq 2 \cdot 10^5)$$$.
The next $$$q$$$ lines describe the queries, with format as stated in the problem statement.
For each query of type $$$Q$$$, output the value in the corresponding location.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$n, q \leq 1000$$$ | $$$30$$$ |
| $$$2$$$ | There is no query of types S | $$$30$$$ |
| $$$3$$$ | The corresponding row / column will be a circular shift in queries of type R and C | $$$30$$$ |
| $$$4$$$ | No additional constraints | $$$60$$$ |
4 7 R 1 1 R 2 3 Q 2 3 C 3 1 S 1 2 C 1 2 Q 4 1
3 2
After the first two queries, the grid becomes
2 3 4 1
1 2 3 4
3 4 1 2
4 1 2 3
For the third query, the number in row $$$2$$$, column $$$3$$$ is $$$3$$$.
Then, in the fourth query, since the third column isn't a circular shift of $$$[1, 2, \dots, n]$$$, nothing happens.
The fifth query swaps the first and second rows, making the grid identical to where it started.
The sixth query performs a circular shift on column $$$1$$$, resulting in the grid
3 2 3 4
4 3 4 1
1 4 1 2
2 1 2 3
For the seventh query, the number in row $$$4$$$, column $$$1$$$ is $$$2$$$.
You are given a simple connected graph with $$$n$$$ vertices and $$$n$$$ edges. A graph is beautiful if all of its connected components are trees of size $$$4$$$. A graph is good if a set of edges can be deleted from the graph to make it beautiful. For each of the $$$n$$$ edges, output whether the graph formed without the edge is good.
In the example above, since the red edges can be deleted to make the resulting graph *beautiful*, the graph above is an example of a *good* graph.
The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10)$$$, representing the number of test cases.
The first line of each test case contains an integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$.
The following $$$n$$$ lines describe the edges. The $$$i$$$th line contains two integers $$$u_i$$$ and $$$v_i$$$ $$$(1 \leq u_i, v_i \leq n, u_i \neq v_i)$$$ such that vertices $$$u_i$$$ and $$$v_i$$$ are connected by an edge.
It is guaranteed that the edges of each test case forms a connected graph and that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$
For each testcase, output a binary string of length $$$n$$$. The $$$i$$$-th character should be $$$1$$$ if the resulting graph after the $$$i$$$th edge is good and $$$0$$$ if it is not.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$\sum n \leq 3000$$$ | $$$60$$$ |
| $$$4$$$ | No additional constraints | $$$90$$$ |
2 4 1 2 2 3 3 4 4 1 8 1 2 2 3 3 4 4 5 5 6 6 7 2 7 6 8
1111 00110110
In the first test case, removing any edge would result in a chain of size $$$4$$$, which is beautiful.
The graph of the second test case is shown in the image above.
You are given an array $$$a$$$ of $$$n$$$ integers and a fixed integer $$$k$$$. Process $$$q$$$ queries of two types:
1. A count query, where you are given $$$l$$$ and $$$r$$$ and count the number of pairs $$$(i, j)$$$ such that $$$l \leq i \lt j \leq r$$$ and $$$a_j - a_i = k$$$.
2. An update query, where you are given $$$p$$$ and $$$x$$$ and set $$$a_p = x$$$.
The first line contains three integers $$$n$$$, $$$q$$$, and $$$k$$$ $$$(1 \leq n, q, k \leq 10^5)$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^5)$$$.
Each of the next $$$q$$$ lines is one of:
For each count query, output the number of pairs $$$(i, j)$$$ such that $$$l \leq i \lt j \leq r$$$ and $$$a_j - a_i = k$$$.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$n, q \leq 1000$$$ | $$$40$$$ |
| $$$2$$$ | There are no update queries | $$$60$$$ |
| $$$3$$$ | No additional constraints | $$$100$$$ |
6 5 3 1 4 7 4 1 4 1 1 6 1 2 5 2 4 7 1 1 4 1 1 6
5 1 3 5
For the first query, $$$(i, j) = (1, 2), (1, 4), (1, 6), (2, 3), (5, 6)$$$ satisfy the constraints.
For the second query, only $$$(i, j) = (2, 3)$$$ satisfies the constraints.
After the third query, the array is modified to $$$[1, 4, 7, 7, 1, 4]$$$.
Alice is chasing Bob through a network of $$$n$$$ rooms. The network is organized as a rooted tree of rooms, numbered from $$$1$$$ to $$$n$$$ and rooted at room $$$1$$$.
At the start of the game, Alice only has control of room $$$A$$$, and Bob is located in room $$$B$$$. It is guaranteed that room $$$A$$$ is the parent of room $$$B$$$.
Each day consists of two sequential phases, in the following order:
1. Bob must choose to either:
2. Alice takes control of exactly one room adjacent to her currently controlled territory. If the newly controlled room is the one Bob is currently in, Bob is captured and the game ends immediately.
Bob wants to maximize the number of days he evades capture, while Alice wants to capture him as quickly as possible. Both players play optimally and have perfect information about the state of the network at all times. Your task is to find the number of days Bob would survive, including the day he is captured.
The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 30000)$$$, representing the number of test cases.
The first line of each test case contains three integers $$$n, K, B$$$ $$$(2 \leq n \leq 2 \cdot 10^5, 1 \leq K \leq n, 2 \leq B \leq n)$$$.
The second line of each test case contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$, where $$$p_i$$$ is the parent of room $$$i$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output a single integer, the number of days Bob survives.
| Subtask | Constraint | Points |
| $$$1$$$ | $$$p_i = i - 1$$$ | $$$40$$$ |
| $$$2$$$ | $$$n \leq 300, \sum n \leq 5000$$$ | $$$40$$$ |
| $$$3$$$ | $$$n \leq 3000, \sum n \leq 50000$$$ | $$$40$$$ |
| $$$4$$$ | No additional constraints | $$$80$$$ |
42 1 216 1 41 2 3 4 58 2 51 2 3 4 2 6 78 3 51 2 3 4 2 6 7
1315
In the fourth example, Bob can teleport to room $$$2$$$, then move down $$$2 \rightarrow 6 \rightarrow 7 \rightarrow 8$$$. It can be proven that Alice will capture Bob in $$$5$$$ days if she moves optimally.
You are given three integers $$$n$$$, $$$m$$$, and $$$k$$$. Your goal is to construct a not necessarily connected simple undirected graph with $$$n$$$ nodes and $$$m$$$ edges (which can be colored red, green, and blue) such that the score is at least $$$k$$$.
A "tetree" is defined as a selection of three edges such that they form a connected graph and connects 4 nodes and the three edges have different colors.
A "rainbow triangle" is defined as a cycle of length $$$3$$$ where each color is used exactly once.
The score of a graph is determined by the formula $$$$$$T - PR$$$$$$
where $$$T$$$ is the number of tetrees, $$$R$$$ is the number of rainbow triangles, and $$$P$$$ is an arbitrary number given in the input.
The first line contains the test number $$$T$$$ $$$(1 \leq T \leq 10)$$$.
The second line contains $$$4$$$ integers: $$$n,m,k,P$$$.
Output $$$m$$$ lines, the $$$i$$$-th line containing three integers $$$u_i,v_i,c_i$$$, representing the two nodes and the color of the edge. In particular, $$$c_i = 0$$$ for a red edge, $$$c_i = 1$$$ for a green edge, and $$$c_i = 2$$$ for a blue edge. The resulting graph should be a simple graph with a score of at least $$$k$$$.
| Test No. | $$$\boldsymbol{n}$$$ | $$$\boldsymbol{m}$$$ | $$$\boldsymbol{k}$$$ | $$$\boldsymbol{P}$$$ |
| $$$1$$$ | $$$4$$$ | $$$6$$$ | $$$7$$$ | $$$0$$$ |
| $$$2$$$ | $$$6$$$ | $$$9$$$ | $$$24$$$ | $$$0$$$ |
| $$$3$$$ | $$$100$$$ | $$$99$$$ | $$$35{,}937$$$ | $$$0$$$ |
| $$$4$$$ | $$$100$$$ | $$$197$$$ | $$$80{,}000$$$ | $$$0$$$ |
| $$$5$$$ | $$$100$$$ | $$$2{,}500$$$ | $$$1{,}850{,}000$$$ | $$$10^5$$$ |
| $$$6$$$ | $$$100$$$ | $$$2{,}501$$$ | $$$1{,}852{,}000$$$ | $$$10^5$$$ |
| $$$7$$$ | $$$100$$$ | $$$3{,}333$$$ | $$$4{,}300{,}000$$$ | $$$10^5$$$ |
| $$$8$$$ | $$$15$$$ | $$$105$$$ | $$$4{,}000$$$ | $$$10^5$$$ |
| $$$9$$$ | $$$100$$$ | $$$4{,}950$$$ | $$$12{,}000{,}000$$$ | $$$10^5$$$ |
| $$$10$$$ | $$$300$$$ | $$$44{,}850$$$ | $$$1{,}000{,}000{,}000$$$ | $$$10^9$$$ |
0 4 3 1 0
1 2 0 2 3 1 3 4 2
The sample case is just for demonstrating the input and output format, and not an actual test that counts towards the score.