Name any show which is referenced in this contest.
The first line of input will contain the testcase number $$$(0 \leq T \leq 20)$$$ where $$$T = 0$$$ refers to the sample. This number is for the grader to use.
Output one string denoting the show. Whether or not the reference shows up in Novice or Advanced does not matter. Only lowercase names without whitespaces and punctuation will be accepted. The string must not exceed $$$100$$$ characters in length. It is guaranteed that any name which is on MyAnimeList will be accepted. If a show has had multiple seasons, stick to the name of the first season.
0
bocchitherock
I don't know how we managed to write a contest without a Bocchi the Rock reference aside from this, but this problem is our Bocchi the Rock reference!
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 1, Advanced 1
Goma has recently developed a newfound interest in mountain climbing and is traveling from left to right through a path of length $$$N$$$ with altitudes assigned to each point. Your task is to determine the number of mountains that Goma will climb during their journey. A mountain is defined as three or more consecutive points with strictly increasing altitudes. It is important to note that if there are more than three points with strictly increasing altitudes, they should be considered as a single mountain. For example, if $$$[l, r]$$$ is a mountain, $$$[l, r-1]$$$ should not be considered as a separate mountain.
The first line contains the integer $$$N$$$ ($$$3 \leq N \leq 10^3$$$), specifying the length of the path Goma will take.
The next line contains $$$N$$$ integers $$$a_1, a_2,\dots, a_N$$$ ($$$1 \leq a_i \leq 10^3$$$) denoting the altitudes of each point of the path.
A single integer denoting the number of mountains Goma will climb.
11 1 2 3 2 4 4 1 4 5 7 3
2
The two mountains here are from points $$$1$$$ to $$$3$$$ with altitudes $$$1, 2, 3$$$ and points $$$7$$$ to $$$10$$$ with altitudes $$$1, 4, 5, 7$$$.
—
Idea: Codicon
Preparation: Bossologist
Occurrences: Novice 2
As is a customary tradition of very hardworking, diligent, productive, and busy problemsetters, Thomas (and other members of the Teamscode problemsetting team) like to play rinbot after meetings.
In a game of rinbot, there are $$$n$$$ rounds and $$$k$$$ problemsetters playing along with Thomas. There is always exactly $$$1$$$ winner per round, and a game is considered a sweep if Thomas is the winner in every single round.
Waymo tells you the conditions of the game and wants to know how many ways different problemsetters can win each round such that Thomas does not get a sweep.
The first line of input will contain two integers $$$n$$$ and $$$k$$$ denoting the number of rounds in a game and the number of problemsetters who are playing aside from Thomas respectively $$$(1 \leq n \leq 10, 1 \leq k \leq 4)$$$.
Output one integer $$$W$$$, the number of ways in which problemsetters (including Thomas) can be assigned to win rounds so that Thomas does not get a sweep.
2 1
3
10 3
1048575
Let's say the $$$1$$$ other problemsetter in the first sample is Waymo. The way games could turn out could be any of the following:
1. Thomas, Thomas
2. Thomas, Waymo
3. Waymo, Thomas
4. Waymo, Waymo
Only in the first scenario Thomas gets a sweep so $$$4 - 1 = 3$$$ is the number of ways a game could end without Thomas sweeping.
The $$$3$$$ problemsetters in the second sample are Waymo, Dustin, and James. Not quite sure how this would help you solve the problem, but good luck!
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 3
Chisato has an $$$N \times N$$$ multiplication table. A multiplication table is an $$$N \times N$$$ matrix where on cell $$$(i, j)$$$ the number $$$i \cdot j$$$ is written for all $$$i \in [{1 \cdots N}]$$$ and $$$j \in [{1 \cdots N}]$$$.
A $$$3 \times 3$$$ mulitplication table looks like this:
$$$$$$ 1, 2, 3 \\ 2, 4, 6 \\ 3, 6, 9 $$$$$$
Takina challenges her to find the smallest positive number that is not present in the multiplication table. Chisato knows how to find the answer, but do you?
The input is one integer $$$N$$$, denoting the dimensions of the multiplication table $$$(1 \lt N \leq 10^5)$$$.
—
Testcases in the subtasks are numbered from $$$1 - 20$$$ with samples skipped.
For testcases $$$1 - 10$$$, $$$1 \lt n \leq 3366$$$.
The remaining testcases do not satisfy any additional constraints.
Output one integer $$$x$$$, the minimum positive integer that is not on the multiplication table.
3
5
3366
3371
A $$$3 \times 3$$$ multiplication table is present in the statement. As can be observed, there is no $$$5$$$ anywhere on it but all other numbers from $$$1 - 4$$$ are present.
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 4
Thomas has two arrays $$$a$$$ and $$$b$$$ both of length $$$n$$$, as well as a value $$$k$$$. He can perform the following operations on $$$a$$$:
A cyclic shift on a subarray $$$[l,r]$$$ of array $$$a$$$ assigns $$$a_i:=a_{i+1}$$$ for $$$l\leq i \lt r$$$ and $$$a_r:=a_l$$$.
Help Thomas find the minimum number of operations to make the two arrays equal.
The first line of the test data contains an integer $$$t$$$ ($$$1\leq t\leq 5\cdot 10^3$$$), denoting the number of test cases.
The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$1\leq k\leq n\leq 2\cdot 10^5)$$$, the length of the arrays and the length of the cyclic shift.
The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1\leq a_i\leq 10^9$$$), denoting the elements of $$$a$$$.
The third line of each testcase contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1\leq b_i\leq 10^9$$$), denoting the elements of $$$b$$$.
The sum of $$$n$$$ over all testcases will not exceed $$$2\cdot 10^5$$$.
Testcases in subtasks are numbered $$$1 - 20$$$ with samples skipped.
Testcases $$$1 - 5$$$ satisfy sum of $$$n$$$ less than or equal to $$$10^3$$$.
The remaining testcases do not satisfy any additional constraints.
Output one integer per test case on its own line that is the minimum number of operations to make $$$a$$$ and $$$b$$$ equal. Note that this number may not fit in a $$$32$$$-bit integer.
33 21 7 31 7 35 51 2 3 4 52 3 4 5 15 35 3 9 10 17 1 2 1 3
0 1 19
17 6964699482 819602309 115120245 28925241 945810909 184051745 67111980796467029 780414521 690030775 504722824 778691724 529821700 720973391
2424878905
In the first test case, the arrays are already equal so the answer is $$$0$$$.
In the second test case, the arrays can be made equal with one cyclic shift, so the answer is $$$1$$$.
In the third test case, one way to get $$$19$$$ operations is to rotate the subarray $$$[3, 5]$$$.
Idea: dutin
Preparation: dutin
Occurrences: Novice 5, Advanced 2
Despite being best girl, Kirisu-sensei still is terrible at math. She has combined the concepts of greatest common factor and least common multiple together!
The greatest common multiple of two numbers $$$a$$$ and $$$b$$$ (gcm) is the largest number that both $$$a$$$ and $$$b$$$ can divide. Since this number is very large (in fact it's infinite), you are asked to find it mod some number $$$c$$$. In this context, largest under mod means the maximum value of $$$(d \text{ mod } c)$$$ over any $$$d$$$ that both $$$a$$$ and $$$b$$$ divide $$$d$$$.
In mathematical terms,
$$$$$$x = \max_{a \mid d, b \mid d}(d \text{ mod } c)$$$$$$
output $$$x$$$ as defined above ($$$a \mid d$$$ means that $$$a$$$ divides $$$d$$$).
The first line contains one integer $$$T$$$, the number of testcases $$$(1 \leq T \leq 3366)$$$.
The following $$$T$$$ lines each contain three integers $$$a, b, c$$$, where $$$a$$$ and $$$b$$$ are the two numbers to find the gcm of and $$$c$$$ is the mod $$$(1 \leq a, b \lt c \leq 10^9)$$$.
For each testcase, output $$$\text{gcm}(a, b) \mod c$$$ or $$$\max_{a \mid d, b \mid d}(d \text{ mod } c)$$$.
5 2 3 10 3 7 10 4 2 2023 33 66 3366 103241 103870 100000007
8 9 2022 3300 100000006
If we pick $$$d = 18$$$ on the first sample, we would output $$$x = 18 \text{ mod } 10$$$. It is impossible to have a better answer. Note that $$$d = 48$$$ or $$$d = 888888$$$ also give a maximal $$$x = 8$$$.
In the second sample, picking $$$d = 189$$$ gives a maximal $$$x = 9$$$.
The two auspicious $$$6$$$-digit numbers are codeforces gym IDs to remind us to upsolve some of our previous contests <3.
—
Idea: 3366
Preparation: 3366
Occurances: Novice 6
You are playing a videogame. In this game, there's an assassin throwing daggers at you, one dagger is thrown every $$$t$$$ seconds and the dagger doesn't take any time to arrive to its destination. You are running through the $$$x$$$-axis of the Euclidean Plane at a constant speed of $$$1$$$ unit per second, and you can decide to stop at any point for some number of seconds. Your goal is to arrive to the coordinate $$$n$$$ in the $$$x$$$-axis without being killed by the assassin.
The game consists of $$$q$$$ levels, each numbered from $$$1$$$ to $$$q$$$, and each level will add one more shield that will be present on this and the next levels. You are safe from a dagger if you are at a shield or at the end point when the dagger is thrown. If not, you will lose. Shields don't vanish when they protect you from a dagger, so you can use the same shield multiple times. Additionally, for each level, $$$t$$$ is equal to the number of that level (for level $$$1$$$, $$$t$$$ will be equal to $$$1$$$; for level $$$2$$$, $$$t$$$ will be equal to $$$2$$$; and so on). Note that this game is a bit weird, so you will always pass to the next level and start again from coordinate $$$0$$$, regardless of whether you have managed to arrive to the coordinate $$$n$$$ or not.
You want to boost your performance so you have decided to calculate if you will be able to pass each level and, if it's possible to do so, the least number of seconds you need to do it.
The first line will consist of two integers, $$$n$$$ and $$$q(2 \leq n \leq 2 \cdot 10^{5}; 1 \leq q \lt n).$$$
Each of the next $$$q$$$ lines will contain one integer $$$x$$$, denoting the coordinate of the new shield. $$$(1 \leq x \lt n).$$$
It is guaranteed that at all times there is at most one shield at any coordinate.
$$$-$$$
Testcases in the subtasks are numbered from $$$1$$$ to $$$20$$$ with samples skipped.
For testcases $$$1-13$$$, $$$2 \le n \le 2000$$$ and $$$1 \le q \le 2000$$$.
The remaining testcases do not satisfy any additional constraints.
You must output $$$q$$$ lines. On the $$$i$$$-th line, you must output $$$-1$$$ if it is impossible to arrive to the coordinate $$$n$$$ in the level $$$i$$$. Otherwise, you must output an integer $$$s$$$, the minimum number of seconds to pass the level $$$i$$$.
7 4 1 2 3 4
-1 -1 -1 7
10 6 2 5 9 1 3 6
-1 -1 -1 13 10 10
In the first sample, there is no way to arrive to coordinate $$$7$$$ in the first three levels. In the fourth level, you could stop at the shield in position $$$4$$$ just in time, when the dagger is thrown, and then arrive at coordinate $$$7$$$.
In the second sample, there is no way to arrive to coordinate $$$10$$$ in the first three levels. For level $$$4$$$, you could go to shields at positions $$$1$$$, $$$5$$$, $$$9$$$ until a dagger was thrown and then arrive to $$$10$$$. For the next levels, you can stay at position $$$5$$$ until the first dagger is thrown and then go to $$$10.$$$
$$$-$$$
Idea: Esomer
Preparation: Esomer
Ocurrences: Novice 7, Advanced 3
Misaka has come up with a very good problem for this contest. Unfortunately, that problem already exists (on at least 3 different online judges!) so she has to add a creative twist to it!
Consider a full binary tree of depth $$$d$$$. Remember a full binary tree with depth $$$d$$$ has $$$2^d - 1$$$ nodes and there is an edge from each node $$$u$$$ $$$(2 \leq u \leq 2^d -1)$$$ to its parent $$$\left \lfloor \frac{u}{2} \right \rfloor$$$. Misaka asks you to find the sum of distances between every pair of nodes on the tree.
Formally if $$$n = 2^d - 1$$$ ($$$n = \#$$$ nodes on the tree), compute:
$$$$$$S = \displaystyle\sum_{i = 1}^{n} \sum_{j = 1}^{n} dist(i, j)$$$$$$
where $$$dist(i, j)$$$ is the minimum number of edges on any path between node $$$i$$$ to node $$$j$$$.
The first line will contain one integer $$$T$$$ denoting the number of multitests $$$(1 \leq T \leq 5)$$$.
The first line of each test will contain one integer $$$d$$$ the depth of the binary tree $$$(1 \leq d \leq 10^5)$$$.
—
Testcases in subtasks are numbered $$$1 - 20$$$ with samples skipped.
Testcases $$$1 - 4$$$ satisfy $$$i$$$'th multitest of the $$$j$$$'th testcase has $$$d = (j-1)\cdot5 + i$$$. For instance testcase $$$2$$$ will consist of $$$d = [6, 7, 8, 9, 10]$$$ across the $$$5$$$ multitests.
Testcases $$$5 - 8$$$ satisfy $$$1 \leq d \leq 10^2$$$.
Testcases $$$9 - 12$$$ satisfy $$$1 \leq d \leq 10^3$$$.
The remaining testcases do not satisfy any additional constraints.
Output one integer $$$S$$$ per testcase denoting the sum of distances across all pairs of nodes on the tree. Since this number may be very large, please find it modulo $$$10^9 + 7$$$.
5 1 2 3 20 3366
0 8 96 443317199 359215119
In the first sample, the tree only has $$$1$$$ node. As $$$dist(1, 1) = 0$$$, the answer would just be $$$0$$$.
In the second sample, there are $$$3$$$ nodes on a full binary tree with depth $$$2$$$. There are edges $$$1 - 2$$$ and $$$1 - 3$$$.
$$$dist(1, 1) = 0$$$
$$$dist(1, 2) = 1$$$
$$$dist(1, 3) = 1$$$
$$$dist(2, 1) = 1$$$
$$$dist(2, 2) = 0$$$
$$$dist(2, 3) = 2$$$
$$$dist(3, 1) = 1$$$
$$$dist(3, 2) = 2$$$
$$$dist(3, 3) = 0$$$
$$$0 + 1 + 1 + 1 + 0 + 2 + 1 + 2 + 0 = 8$$$ so $$$8$$$ is the answer.
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 9, Advanced 4
Goma has been enjoying mountain climbing so much lately that they want to take Peach with them! There is a path of length $$$N$$$ with varying altitudes, and Peach wants to know how many distinct points they can see from certain spots on the path. However, fog is forecasted for the day of their trip, so Peach wants to take that into account when calculating the visible points. Specifically, if a point $$$p$$$ has altitude $$$a_p$$$ and the fog has altitude $$$f$$$, then Peach can see all points $$$q$$$ such that:
Note that Peach can always see the spot they are currently on.
The first line contains two integers $$$N$$$ $$$(1 \leq N \leq 10^6)$$$ and $$$Q$$$ $$$(1 \leq Q \leq 10^5)$$$, where $$$N$$$ is the length of the mountain path and $$$Q$$$ is the number of queries Peach would like to make.
The next line contains $$$N$$$ space separated integers $$$a_1, a_2,\ldots, a_N$$$ where $$$a_i$$$ $$$(1 \leq a_i \leq 10^9)$$$ is the altitude of point $$$i$$$ on the path.
The last $$$Q$$$ lines each contain two integers $$$p$$$ $$$(1 \leq p \leq N)$$$ and $$$f$$$ $$$(1 \leq f \leq 10^9)$$$ which represents a request Peach has to find the number of spots on the mountain visible from point $$$p$$$ given there is fog at altitude $$$f$$$.
Testcases in subtasks are numbered from $$$1$$$ to $$$20$$$ with samples skipped.
Testcases $$$1-5$$$ the fog is negligible (has an altitude of $$$1$$$).
Testcases $$$6-20$$$ have no additional constraints.
$$$Q$$$ lines with a single integer where the $$$i$$$'th line contains the answer to Peach's $$$i$$$'th query.
10 3 1 2 3 2 4 4 2 4 5 3 2 3 3 2 5 2
2 3 4
The answer to Peach's second query is $$$3$$$ as they can see points $$$2$$$ through $$$4$$$. Note that they cannot see point $$$1$$$ because of the fog at altitude $$$2$$$.
—
Idea: Bossologist
Preparation: Bossologist
Occurrences: Advanced 5
Quintessential Quintuplets is a good show but let's be real here, only two of the quintuplets are actually quintessential.
Nino and Miku are playing a game on an array $$$a$$$ of $$$n$$$ positive integers. In one turn, a player can pick any element in the array and floor divide it by $$$2$$$ or $$$3$$$ as long as the resulting number remains strictly positive. Nino goes first and the player who cannot make a move loses.
A possible game on the array $$$a = [1, 2, 5]$$$ could go as follows:
1. Nino divides $$$a_3$$$ by $$$3$$$ and is left with $$$a_3 = \left \lfloor \frac{5}{3} \right \rfloor = 1$$$ with the array now becoming $$$[1, 2, 1]$$$
2. Miku can then divide $$$a_2$$$ by $$$2$$$ leaving the array as $$$[1, 1, 1]$$$. Note that Miku could not have divided by $$$3$$$ since $$$\left \lfloor \frac{2}{3} \right \rfloor = 0$$$ and that would no longer be positive.
3. Nino then loses since she cannot divide any of the remaining elements by any value. In this game, Nino did not play optimally and lost.
When given the array, assuming both girls play perfectly, who will win?
The first line will contain one integer $$$T$$$, the number of testcases $$$(1 \leq T \leq 10^5)$$$.
The first line of each testcase will contain one integer $$$n$$$, the length of the array $$$(1 \leq n \leq 10^5)$$$.
The following line will contain $$$n$$$ numbers, the array $$$a$$$ $$$(1 \leq a_i \leq 10^9)$$$.
The sum of $$$n$$$ across all testcases will not exceed $$$10^5$$$.
—
Testcases in subtasks are numbered $$$1 - 20$$$ with samples skipped.
Testcases $$$1 - 5$$$ satisfy $$$n = 1, 1 \leq a_i \leq 10^6$$$.
Testcases $$$6 - 10$$$ satisfy $$$n = 1$$$.
Testcases $$$11 - 15$$$ satsify $$$1 \leq a_i \leq 10^6$$$.
The remaining testcases do not satisfy any additional constraints.
For each testcase output, one string "Nino" or "Miku" (without the quotes) per line, indicating which girl would win with perfect play.
5 3 1 2 5 3 2 3 4 2 3366 3366 1 1000000000 7 1 2 3 4 5 6 7
Nino Nino Miku Nino Miku
In the first sample the winning strategy is as follows. Nino divides $$$a_3$$$ by $$$2$$$, the array becomes $$$[1, 2, 2]$$$. Whichever value Miku picks to divide by $$$2$$$, Nino can pick the other one and leave Miku out of moves.
In the second sample, if Nino divides $$$a_3$$$ by $$$3$$$, the array becomes $$$[2, 3, 1]$$$. Whatever value Miku picks, Nino can always win.
In the third sample, Miku can mirror any move Nino makes on the other pile. This ensures that Miku can always win.
In the fourth sample, Nino wins. Yeah, I can't be bothered to explain that one.
—
Idea: 3366, JamesL
Preparation: 3366
Occurrences: Novice 10, Advanced 6
Hina has a string $$$s$$$ of lowercase letters and question marks. She wants to fill each question mark with a lowercase letter so that she is left with a string of only lowercase letters. Hina will then count over all permutations of letters in her string, the number of unique strings that can be formed. For instance, the string $$$aab$$$ has $$$6$$$ permutations, $$$[aab, aba, aab, aba, baa, baa]$$$ but only form $$$3$$$ unique strings.
Over all $$$26^{\#\text{ of ?'s}}$$$ ways Hina can fill in the question marks, what is the expected number of unique strings that can be formed?
The first line will contain one integer $$$T$$$, the number of testcases $$$(1 \leq T \leq 500)$$$.
Each following line will contain a string $$$s$$$, the string Hina wants you to find the answer for. $$$s$$$ will only contain lowercase letters or question marks $$$(1 \leq |s| \leq 10^3)$$$.
It is guaranteed that the sum of $$$|s|$$$ over all testcases will not exceed $$$5 \cdot 10^3$$$.
—
Tests in subtasks will be numbered from $$$1 - 20$$$ with samples ignored.
Tests $$$1-4$$$ will have no strings that contain question marks.
Tests $$$5-6$$$ will have all strings only contain question marks.
Tests $$$7-10$$$ will have the sum of all string lengths not be greater than $$$100$$$.
The remaining testcases have no additional constraints.
For each testcase, output a single integer $$$E$$$, the expected number of permutations over all ways to fill in the question marks modulo $$$10^9 + 7$$$. The expected value can be represented as fraction $$$\frac{x}{y}$$$ and you will output $$$E$$$ where $$$x = E \cdot y \mod 10^9 + 7$$$.
7 a?b bestgirl? rem?? whoisrem??? trust ?? a?
538461548 615691672 165680579 840240076 60 423076928 423076928
2 whatdoyoudoattheendoftheworld?areyoubusy?willyousaveus? shuumatsunanishitemasuka?isogashiidesuka?sukuttemoratteiidesuka?
954747861 94849604
For the string $$$a?b$$$, when we fill the $$$?$$$ in for $$$a$$$ or $$$b$$$, there are $$$3$$$ permutations but for any letter, there are $$$6$$$. This gives us an expected value of $$$\frac{3 \cdot 2 + 6 \cdot 24}{26} = 538461548 \mod 10^9 +7$$$.
For the string $$$trust$$$, there are no $$$?$$$'s and there can be shown to exist exactly $$$60$$$ unique strings that can be formed from permuting the letters, giving an expected value of $$$60$$$.
Both strings $$$a?$$$ and $$$??$$$ have an expected value of $$$\frac{1 \cdot 1 + 2 \cdot 25}{26} = \frac{51}{26} = 423076928 \mod 10^9 + 7$$$.
For the second sample, you should watch that particular anime <3.
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 11
Meruem the ant is on an infinite brick wall, where every brick is a $$$1$$$ by $$$2$$$ inch rectangle, and each row is a duplicate of the previous row, shifted $$$1$$$ inch to the right. Every day he starts on the lower left point of a brick and travels in a straight line to the point $$$x$$$ inches to the east and $$$y$$$ inches to the north. How many bricks does Meruem pass through?
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ $$$-$$$ the number of test cases. The description of the test cases follows.
Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ $$$(1 \le x, y \le 10^{10})$$$.
It is guaranteed that $$$x \cdot y \le 10^{10}$$$.
The first five test cases (not including the sample) satisfy $$$x, y \le 1000$$$.
For each test case, print one integer — the number of bricks Meruem passes through.
3 3 3 5 2 5 1
3 4 3
Travelling to $$$(3,3)$$$ goes through three bricks.
Travelling to $$$(5,2)$$$ goes through four bricks.
Travelling to $$$(5,1)$$$ goes through three bricks
Idea: thehunterjames
Preparation: thehunterjames, Esomer
Occurrences: Novice, problem 8
There's an explorer entering a magic labyrinth. As he enters, the entrance closes behind him and the labyrinth starts filling up with poisonous gas. Once he realises, he asks for your help so that he is exposed to the minimum amount of gas possible.
The labyrinth can be represented as a simple directed graph of $$$n \le 100$$$ vertices, numbered from $$$1$$$ to $$$n$$$, and $$$m \le 1000$$$ edges. The explorer is initially at vertex $$$1$$$. The amount of gas in each vertex can be represented as an array $$$a$$$, being $$$a_{i}$$$ the amount of gas at vertex $$$i$$$.
The gas will last at the labyrinth for exactly $$$k$$$ seconds. After that, the explorer will be free again. Each second, the explorer can either move to any vertex $$$v$$$ such that there exists an edge from $$$u$$$ to $$$v$$$ or stay at vertex $$$u$$$, being $$$u$$$ the vertex he is currently at, but only after being exposed to the gas in vertex $$$u$$$. Due to the magic of the labyrinth, each second, after the explorer is exposed to the gas at vertex $$$u$$$, the array $$$a$$$ will cyclically shift once to the left (i.e. simultaneously set for all $$$i$$$, $$$1 \leq i \lt n$$$, $$$a_{i}$$$ to $$$a_{i+1}$$$ and $$$a_{n}$$$ to $$$a_{1}$$$).
You need to determine what is the minimum amount of gas the explorer can be exposed to. Note that the explorer doesn't need to return to vertex $$$1$$$.
The first line contains the number of vertices, edges and seconds respectively, $$$n(1 \leq n \leq 100)$$$, $$$m(0 \leq m \leq min(1000, n\cdot(n-1)))$$$ and $$$k(1 \leq k \leq 10^{9})$$$.
The next line contains $$$n$$$ integers, $$$a_{1},a_{2}\ldots,a_{n} (0 \leq a_{i} \leq 10^{9})$$$.
Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$, meaning that there's an edge from $$$u$$$ to $$$v(1 \leq u,v \leq n; u \neq v)$$$.
Output a single integer, the minimum amount of gas the explorer can be exposed to.
6 8 4 9 8 2 8 8 0 1 2 5 4 6 3 4 3 2 5 1 6 5 3 6 4
18
6 10 7 7 6 0 1 0 6 1 4 1 5 2 5 3 2 3 5 4 2 4 3 4 5 6 3 6 5
8
4 4 5 0 1 2 3 1 4 4 3 3 2 2 1
0
For the first sample, an optimal strategy would be:
For the second sample, an optimal sequence of nodes (representing the node where he's at each second) would be $$$[1,4,3,2,5,5,5]$$$.
For the third sample, the explorer can always go to a vertex where the amount of venom is 0.
$$$-$$$
Idea: 3366, thehunterjames and Esomer
Preparation: Esomer
Ocurrences: Advanced 8
After listening to Mask by Dream, Asahi decided to start wearing a mask and a green hoodie. Unfortunately, this did not change the fact that she is still failing all her classes. Thus, Asahi now turns to you for help on her test.
In the test, Asahi is given a tree with $$$N (1 \le N \le 5 \cdot 10^5)$$$ nodes. The $$$i$$$th edge in the tree between nodes $$$u_i$$$ and $$$v_i$$$ has a weight of $$$w_i (0 \le w_i \le 10^9)$$$. The goal is to choose two node disjoint (cannot share any nodes) paths in the tree. Asahi's score will then be $$$\text{min}(\text{sum of weight of path 1}, \text{sum of weight of path 2})$$$. Asahi wants to score as high as possible on the test, so she asks you to find her maximum possible score.
The first line contains one integer $$$T (1 \le T \le 10)$$$, denoting the number of test cases.
The first line of every test case will contain a single integer $$$N (1 \le N \le 5 \cdot 10^5)$$$, the size of the tree.
The next $$$N - 1$$$ lines of every test case will each contain three integers $$$u_i$$$, $$$v_i$$$, $$$(1 \le u_i, v_i \le N)$$$ and $$$w_i$$$ $$$(0 \le w_i \le 10^9)$$$, denoting the two endpoints and weight of the $$$i$$$th edge respectively.
It is guaranteed that $$$\sum N \le 5 \cdot 10^5$$$.
In testcase $$$1$$$, $$$\sum N \le 50$$$.
In testcases $$$2 - 4$$$, $$$\sum N \le 5000$$$.
In testcases $$$5$$$, $$$w_i = 0$$$.
In testcase $$$6 - 14$$$, $$$\sum N \le 2 \cdot 10^5$$$.
In testcases $$$15 - 20$$$, there are no further restrictions.
For each test case, output a line containing the maximum score Asahi can achieve for that test case.
1 6 1 2 1 2 3 1 1 4 3 4 5 5 4 6 5
2
Idea: oursaco
Preparation: oursaco
Occurrences: Advanced 9
Note the higher time limit than usual.
You are given an array $$$a$$$ of $$$n$$$ integers and $$$q$$$ queries to process.
Each query consists of three integers, $$$l$$$, $$$r$$$ and $$$x$$$, and indicates that each value of $$$a$$$ between $$$l$$$ and $$$r$$$, inclusive, is incremented by $$$x$$$. Note that the updates are not independent, so the increments persist for the following queries.
After each query, print the minimum $$$i$$$ that satisfies the following conditions:
The first line contains two integers, $$$n$$$ and $$$q$$$, the size of the array and the number of queries, respectively. $$$(2 \leq n \leq 10^{6}; 1 \leq q \leq 10^{6})$$$.
The next line contains $$$n$$$ integers, $$$a_{1}a_{2}\ldots a_{n}$$$. $$$(-10^{9} \leq a_{i} \leq 10^{9})$$$.
The following $$$q$$$ lines will each contain three integers, $$$l$$$, $$$r$$$ and $$$x$$$. $$$(1 \leq l \leq r \leq n; 1 \leq x \leq 10^{9})$$$.
It is guaranteed that the sum of $$$(r - l + 1) \cdot x$$$ over all queries is never greater than $$$10^{18}$$$.
$$$-$$$
Testcases in the subtasks are numbered from $$$1−20$$$ with samples skipped.
For testcases $$$1-5$$$, $$$2 \le n \le 1000$$$ and $$$1 \le q \le 1000$$$.
The remaining testcases do not satisfy any additional constraints.
For each query, output the minimum $$$i$$$ that satisfies the following conditions:
6 5 2 -1 1 0 0 1 4 5 1 1 1 4 2 2 9 4 6 20 1 1 3
3 -1 2 2 4
5 10 9 -17 -6 1 -58 1 4 4 3 4 5 1 4 7 5 5 1 2 2 3 5 5 6 5 5 7 2 3 10 2 4 7 2 4 7
4 3 -1 -1 -1 -1 -1 -1 -1 2
Explanation of the first sample:
$$$-$$$
Idea: Esomer
Preparation: Esomer
Ocurrences: Advanced 10
Touya Mochizuki was struck by a bolt of lightning. Fortunately, instead of dying, he is sent to another world with his smartphone. Unfortunately, even in this generic new fantasy world, Touya is still unable to escape from generic range query problems!
Touya has an array $$$a$$$ of length of $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$). He is now tasked with $$$Q$$$ ($$$1 \le Q \le 2 \cdot 10^5$$$) queries of two possible types. Queries of type $$$2$$$ will add a value $$$v$$$ to every $$$a_i$$$ for $$$l \le i \le r$$$. Queries of type $$$1$$$ will ask him what is the sum of all subarrays in the range $$$l \dots r$$$, that is to say, $$$\displaystyle \sum_{i=l}^{r} \sum_{j=i}^{r} \sum_{k=i}^{j} a_k$$$. Since these values can be quite large, please output them modulo $$$10^9 + 7$$$
The first line contains two integers denoting $$$N$$$ and $$$Q$$$ ($$$1 \le N, Q \le 2 \cdot 10^5$$$)
The second line contains $$$N$$$ integers, $$$a_1, a_2, \dots, a_n$$$. ($$$0 \le a_i \le 10^9$$$)
The next $$$Q$$$ lines will each contain a single integer, $$$t$$$, denoting the type of the query. If $$$t$$$ is $$$1$$$, then it will be followed by two integers $$$l$$$ and $$$r$$$. If $$$t$$$ is $$$2$$$, then it will be followed by three integers $$$l$$$, $$$r$$$, and $$$v$$$. ($$$1 \le l \le r \le N, 1 \le v \le 10^9$$$)
In testcase $$$1$$$, $$$N, Q \le 500$$$.
In testcases $$$2 - 4$$$, $$$N, Q \le 5000$$$.
In testcases $$$5 - 9$$$, In every query of type $$$2$$$, it is guaranteed that $$$l_i = r_i$$$.
In testcase $$$10$$$, there are no queries of type $$$1$$$.
In testcases $$$11 - 20$$$, there are no further restrictions.
For each query of type $$$1$$$, output a line containing its corresponding answer.
5 5 1 2 3 4 5 1 1 5 1 2 5 2 1 3 4 1 1 5 1 2 5
105 70 193 110
Idea: oursaco
Preparation: oursaco
Occurrences: Advanced 11
You are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. How many numbers between $$$l$$$ and $$$r$$$ $$$(1\le l \le r\le10^{18})$$$ can be expressed in the form $$$\displaystyle\sum_{i=1}^{n}\lfloor a_ix\rfloor$$$, where $$$x$$$ is a real number, and $$$\lfloor y\rfloor$$$ denotes greatest integer less than or equal to $$$y$$$?
The first line consists of three integers $$$n$$$, $$$l$$$, and $$$r$$$ $$$(1 \leq n \leq 10^{5}, 1 \le l \le r \le 10^{18})$$$.
The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^5)$$$.
The first $$$5$$$ test cases (not including the sample) satisfy $$$n \le 100$$$, $$$a_i \le 1000$$$, $$$l \le r \le 1000$$$.
The next $$$10$$$ test cases satisfy $$$n \le 10^5$$$, $$$l \le r \le 10^9$$$.
The last $$$5$$$ test cases do not have any extra constraints.
Print a single integer $$$-$$$ the number of reachable integers in the range $$$[l, r]$$$.
2 2 8 2 3
6
$$$x=\frac{1}{2}$$$ gives a sum of $$$2$$$.
$$$x=\frac{2}{3}$$$ gives a sum of $$$3$$$.
$$$x=1$$$ gives a sum of $$$5$$$.
$$$x=\frac{4}{3}$$$ gives a sum of $$$6$$$.
$$$x=\frac{3}{2}$$$ gives a sum of $$$7$$$.
$$$x=\frac{5}{3}$$$ gives a sum of $$$8$$$.
It can be shown that it is impossible to attain a sum of $$$4$$$.
Idea: thehunterjames
Preparation: thehunterjames
Occurrences: Advanced, 7
To celebrate the airing of Tonikawa Season 2, the Yuzaki couple has decided to host a giant game of bingo at the bathhouse. There are $$$N$$$ people, conveniently numbered with an ID from $$$1$$$ to $$$N$$$, each with a $$$5$$$ by $$$5$$$ bingo board where each number is in the range $$$[1, k]$$$. Nasa will then call out the numbers from $$$1$$$ to $$$k$$$ in a certain order. The first person to have a full row or column of numbers that have been called already on their board wins (for simplicity diagonals are ignored in this problem). In the case of a tie, the person with the lowest ID wins. Nasa is going to ask you many different orders, and for each order he wants you to find the person who will win.
The first line contains two integers $$$N$$$ and $$$k$$$, the number of people and the maximum number on any board $$$(1 \leq N \leq 10^5, 1 \leq k \leq 25)$$$.
Following this will be $$$N$$$ $$$5 \times 5$$$ boards $$$B_i$$$, denoting the bingo board of the $$$i$$$'th contestant. It is guaranteed that all numbers present on the board will be in the range $$$[1, k]$$$ but not all numbers are guaranteed to be distinct.
The next line will contain $$$1$$$ integer $$$q$$$, denoting the number of queries Nasa will ask you $$$(1 \leq q \leq 5 \cdot 10^4)$$$.
The following $$$q$$$ lines will each contain $$$k$$$ integers $$$O_i$$$ denoting the order the numbers are called in the $$$i$$$'th query. It is guaranteed that $$$O_i$$$ is a permutation of the numbers $$$1$$$ to $$$k$$$.
—
Testcases in subtasks are numbered from $$$1 - 20$$$ with samples skipped.
Testcases $$$1-4$$$ satisfy $$$N = 1$$$.
For testcases $$$5 - 8$$$, $$$k = 16$$$.
For testcases $$$9 - 12$$$, $$$16 \leq k \leq 20$$$.
For testcases $$$13 - 16$$$, $$$1 \leq q \leq 1 \cdot 10^4$$$.
Due to easy test data (a mistake on my part), many unintended solutions can ac. So as a bonus problem, try to solve $$$k = 27$$$ for the inteded solution.
The remaining testcases do not satisfy any additional constraints.
For each query output a line with two integers, $$$w$$$ and $$$l$$$, the ID of the winner and the last number that was called before he won. In the case of multiple winners, output the winner with the lowest ID. Under the constraints of the problem, at least one person will win every round.
1 25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1 6 11 16 2 7 12 17 3 8 13 18 4 9 14 19 25 21 22 23 24 5 10 15 20 1 2 3 4 6 7 8 10 11 12 14 15 16 18 19 20 22 23 24 25 5 9 13 17 21 16 14 13 22 3 21 15 23 20 9 11 24 4 8 1 12 7 17 19 5 2 10 6 25 18
1 5 1 21 1 5 1 12
In the first query, the first row of $$$[1, 2, 3, 4, 5]$$$ was completed with $$$5$$$ being the last number called.
In the second query, the first column of $$$[1, 6, 11, 16, 21]$$$ was completed with $$$21$$$ being the last number called.
In the third query, the first row and last column, $$$[1, 2, 3, 4, 5]$$$ and $$$[5, 10, 15, 20, 25]$$$ respectively, were completed after $$$5$$$ was called.
As a reminder, diagonals are not counted in this problem as a winning condition as opposed to regular bingo.
You can do it! Tsukasa smiles down on you!
—
Idea: 3366
Preparation: 3366
Occurrences: Advanced 12