The problem setting team (well codicon and 3366 exclusively) put their heads together to present to you the ultimate anime-themed problem! You will have to output the name of the best waifu.
You are given an integer $$$T$$$, the current testcase $$$(0 \leq T \leq 20)$$$. Note that this is for the checker to use.
Output one token (string with no whitespaces) of length no more than $$$100$$$ with all lowercase letters denoting the best waifu. If there are multiple answers, output any.
Remember, confidence is key!
0
thomas
Rest assured, the sample is always correct.
—
Idea: codicon, 3366
Preparation: 3366
Occurrences: Novice 1, Intermediate 1, Advanced 1
Bossologist is slowly losing his sanity! Bossologist starts off with $$$S$$$ sanity points, for every email Chessbot sends from polygon, he loses $$$1$$$ sanity point. The problem writing process lasts $$$N$$$ days, where each day Chessbot sends between $$$0$$$ and $$$1000$$$ emails (inclusive). Given that Bossologist will gain $$$1$$$ sanity point for every $$$K$$$ days in a row that he doesn't get an email, calculate the number of sanity points he has at the end of $$$N$$$ days.
Note: It is guaranteed that Bossolgist's sanity will always be non-negative for the entire problem writing process.
The first line contains $$$N$$$ ($$$1 \leq N \leq 10^5$$$), $$$S$$$ ($$$1 \leq S \leq 10^9$$$), and $$$K$$$ ($$$1 \leq K \leq 1000$$$).
The next line contains $$$N$$$ integers where the $$$i$$$'th number denotes the number of emails Chessbot sends on day $$$i$$$.
Output Bossologist's sanity at the end of the $$$N$$$ days.
7 10 3 3 0 0 0 0 0 0
9
On the first day Bossologist loses $$$3$$$ sanity points since Chessbot sent $$$3$$$ emails. However he then gains $$$2$$$ sanity points back since by day $$$7$$$ Bossologist has not recieved an email for $$$6$$$ days. So he therefore ends the $$$7$$$ days with a sanity of $$$9$$$.
$$$-------------------------------------------------$$$
Idea: Bossologist
Preparation: Bossologist
Occurences: Novice 2
Davin is a very busy man, and he likes to get his schedule set on the day before a new year begins. The new year will be $$$2023$$$, and Davin has $$$N$$$ different events he needs to attend. He has those $$$N$$$ events represented by $$$A, B, C$$$, where $$$A$$$ and $$$B$$$ represent the month and day of the start date of the event, and $$$C$$$ represents how many days it takes to repeat that event. For example, if an event starts on August $$$6$$$th and repeats every $$$11$$$ days (August $$$6$$$, August $$$17$$$, August $$$28$$$, September $$$8$$$...), it would be represented by "$$$8$$$ $$$6$$$ $$$11$$$".
Davin would like to go on a vacation sometime during $$$2023$$$; thus, he wants to find the largest pocket of time where there are no events. Given the events Davin has during $$$2023$$$, output the largest pocket of time, in days, that he could go on a vacation.
The first line will have $$$N$$$, where $$$N$$$ $$$1 \leq N \leq 100$$$ represents the number of events Davin has in $$$2023$$$.
The next $$$N$$$ lines will have $$$A, B, C$$$ $$$1 \leq C \leq 364$$$ where $$$A$$$ represents the month and $$$B$$$ represents the day of the date in which the event starts, and $$$C$$$ represents how many days between repeats of the event. It is guaranteed that $$$A$$$ and $$$B$$$ represent valid days in the calendar of the year $$$2023$$$.
Find the biggest pocket of time, in days, in which Davin can go on a vacation.
3 3 27 4 6 24 2 8 6 11
85
After Davin marks all his events and when they will happen, the largest pocket of time he could go on vacation for is $$$85$$$ days, all the days before the first event of his year which starts on March $$$27$$$th.
$$$---------------------------------$$$
Idea: Spark
Preparation: Spark, Codicon + Bossologist
Occurrences: Novice 5, Intermediate 2
Thomas is doing a contest! He is facing many different problems he wants to solve, for a chance to be able to game again. The contest itself is structured like a $$$n \times m$$$ grid, where each cell entry represents the points Thomas gets if he solves that particular problem. During the contest, Thomas will choose exactly one sub-rectangle of problems, and solve all of the problems inside it to earn those points. Thomas wants to make sure his points earned is as maximal as possible. However, there is one problem in this contest (let's call it problem E) that gives a negative amount of points. Help Thomas find the maximum number of points he can earn by solving one sub-rectangle of the problems! (Please note that Thomas cannot skip problems in the rectangle that he picked).
The first line contains two integers, $$$n$$$ and $$$m$$$ $$$(1 \leq n, m \leq 500)$$$ denoting the dimensions of the grid. It is guaranteed that the area of the grid is strictly greater than $$$1$$$.
The following $$$n$$$ lines contain $$$m$$$ integers each, the respective row of the grid. Each element in the grid will have an absolute value $$$\leq 100$$$.
There will be exactly one negative value in the entire grid.
One integer, denoting the maximum number of points Thomas can earn by solving one sub-rectangle.
3 3 5 5 5 5 -40 5 5 5 5
15
1 4 0 33 -1 66
98
For the first sample, no matter how you look at it, Thomas does not gain from solving the middle problem worth $$$-40$$$. So the maximum number of points he can earn is $$$15$$$ from either solving the top row, bottom row, rightmost column, or leftmost column.
In the second sample, Thomas can solve the entire grid, since the gains from the $$$33$$$ and $$$66$$$ outweigh the $$$-1$$$ in the middle.
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 4, Intermediate 3
Bossologist is in a group with $$$N$$$ people (including himself) that has recently won the lottery! Because the group is very fair, they deposit $$$100$$$ dollars into each person's bank account. Everyone is excited to spend their money, but they make sure first to keep track of their purchases in a spending list. The list is of length $$$Q$$$ and contains the purchases of each person and they amount they spent, in chronological order.
However, the person who has the longest consecutive streak of spending must pay a tax of $$$A$$$ dollars to each person in the group, where $$$A$$$ represents the length of the longest consecutive streak. If multiple people have the same longest consecutive streak, the person who got the longest consecutive streak first must pay the tax.
The group wants to know the difference in dollars between the person with most and least amount of money in their bank account after all the purchases are made and taxes are paid. Note that the amount of money in a bank account can be negative.
The first line will include $$$N$$$ ($$$1 \leq N \leq 100$$$), and $$$Q$$$ ($$$1 \leq Q \leq 1000$$$).
The next $$$Q$$$ lines describe the spending list. Each line will include $$$P$$$, the name of the person, and $$$S$$$ ($$$1 \leq S \leq 10^3$$$), how much they spent. Each name will not exceed $$$1000$$$ characters, and furthermore, all $$$N$$$ people will appear at least once on the spending list.
Give the difference, in dollars, between the person with the most and least amount of money in their bank account.
3 7 Bossologist 10 Bossologist 5 Bossologist 20 Codicon 50 Spark 15 Spark 15 Bossologist 5
20
First, each person receives $$$100$$$ dollars in their bank account. In total Bossologist spends $$$40$$$, and so he ends up with $$$60$$$ dollars. Codicon spends a total of $$$50$$$ dollars and so he ends up with $$$50$$$ dollars. And finally Spark spends a total of $$$30$$$ dollars, and so he ends up with $$$70$$$. Now, it's time to pay taxes! Since Bossologist has the highest consecutive streak of $$$3$$$, Bossologist must pay $$$3$$$ dollars to each other person. After paying taxes, Bossologist now has $$$54$$$ dollars, Codicon has $$$53$$$ dollars, and Spark has $$$73$$$ dollars. Spark has the most with $$$73$$$ dollars, and Codicon has the least with $$$53$$$ dollars, so the answer is $$$73 - 53 = 20$$$ dollars.
—
Idea: Spark
Preparation: Spark, Bossologist, Codicon
Occurrences: Novice 5, Intermediate 2
Misaka is confused. She is staring at her front yard, a garden of length $$$N$$$, and it seems to be lined with trees... and her clones? As Misaka looks at her front yard, she notices that for certain segments of her front yard there are an equal amount of clones and trees. Her memory has gotten worse so she has forgotten what her front yard looked like on that day. However, she still remembers $$$M$$$ intervals where the number of clones and trees were the same. Misaka wants you to find any possible arrangement of clones and trees such that it matches with the intervals she remembers.
The first line contains an integer $$$T$$$, denoting the number of testcases $$$(1 \leq T \leq 10)$$$.
Each test case starts off with one line containing two integers $$$n, m$$$, the length of her front yard and the number of segments she remembers. $$$(1 \leq n \leq 100, 1 \leq m \leq 1000)$$$.
The following $$$m$$$ lines containing two integers each $$$l,r$$$, $$$(1 \leq l \leq r \leq n)$$$ denoting that the segment $$$[l \cdots r]$$$ had the same number of clones as trees.
It is guaranteed the sum of $$$n$$$ over all test cases is not greater than $$$100$$$ and the sum of $$$m$$$ over all test cases is not greater than $$$1000$$$.
For each test case, if there is a solution, output "Y" on one line, then output a string length $$$n$$$ of "M"'s and "T"'s where an "M" denotes a clone and "T" denotes a tree on the next line. For the string outputted, it must satisfy every one of the $$$m$$$ constraints specified in the input. If there are multiple solutions, output any.
If there is no solution, then just output "N" on its own line.
2 5 3 1 4 4 5 2 3 5 1 1 5
Y MMTTM N
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 6, Intermediate 5
Peach and Goma have taken up a new hobby recently. Sometimes they decide to get together to look at a number $$$x$$$ and compute $$$x \oplus (x + 1)$$$, where $$$\oplus$$$ is the bitwise XOR operator. Today they computed this value for all integers from $$$A$$$ to $$$B$$$ inclusive, and Peach and Goma are curious about their results. For a given number $$$M$$$ they would like you to find the number of integers $$$x$$$ ($$$A \leq x \leq B$$$) such that $$$x \oplus (x + 1) \geq M$$$.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^3)$$$, the number of test cases. Then $$$T$$$ test cases follow.
Each test case has a single line with the integers $$$A$$$, $$$B$$$, $$$M$$$ respectively, where ($$$1 \leq A \leq B \leq 10^9$$$, $$$1 \leq M \leq 10^9$$$).
$$$T$$$ lines with one integer each denoting the number of integers $$$x$$$ ($$$A \leq x \leq B$$$) such that $$$x \oplus (x + 1) \geq M$$$ for each test case.
2 3 5 2 15 20 10
2 1
Note that $$$3 \oplus 4 = 7$$$, $$$4 \oplus 5 = 1$$$, and $$$5 \oplus 6 = 3$$$, therefore there are two integers where the computed value is greater than $$$2$$$.
$$$-------------------------------------------------$$$
Idea: Bossologist
Preparation: Bossologist
Occurences: Novice 7, Intermediate 4, Advanced 2
This statement is entirely fictional and no such events will ever come to happen in real life. Since in accordance with popular belief, Waymo is in fact broke.
Waymo has decided to make the class he is TA'ing for solve Lattice MST (from the Teamscode Summer 2021 contest). To help keep the students motivated to solve the problem, he will buy each student a cup of milk tea (with aloe vera instead of boba since aloe vera $$$ \gt $$$ boba). However, Waymo does not feel the obligation to buy milk tea for someone with zero trust. Trust is calculated as follows:
Every student $$$i$$$ starts of with $$$t_i$$$ trust. Then over the course of $$$Q$$$ days, if by day $$$d$$$, a student has not solved Lattice MST, their trust will decrease by $$$x_d$$$. Note that similar to real life, milk tea is bought before trust decreases. Also, note that trust is never negative. If a person ever has negative trust, their trust is set back to $$$0$$$.
So over the course of the $$$Q$$$ days, you have to output how many cups of milk tea Waymo has to buy on each day as well as the sum of trusts over all students. Assume that none of the students can solve Lattice MST.
The first line contains two integers $$$N$$$ and $$$Q$$$ $$$(1 \leq N, Q \leq 2 \cdot 10^5)$$$, the number of students and the number of days.
The second line contains $$$N$$$ integers, where the $$$i$$$'th integer is $$$t_i$$$ $$$(0 \leq t_i \leq 10^9)$$$, the initial trust of the $$$i$$$'th student.
In the following $$$Q$$$ lines, each line contains one integer $$$x_i$$$ $$$(0 \leq x_i \leq 10^9)$$$, denoting the amount of trust lost if a student does not finish by the end of day $$$i$$$.
Output $$$Q$$$ lines containing $$$2$$$ integers per line, where the first integer on a line is the number of cups of milk tea Waymo has to buy and the second integer is the sum of trusts over all students.
6 5 10 0 3 3 6 6 2 0 3 3366 1
5 28 5 18 5 18 3 7 0 0
Remember that milk tea is bought before trust is lost.
The "trust table" for each day is as follows:
Day $$$1$$$: $$$[10, 0, 3, 3, 6, 6]$$$
Day $$$2$$$: $$$[8, 0, 1, 1, 4, 4]$$$
Day $$$3$$$: $$$[8, 0, 1, 1, 4, 4]$$$
Day $$$4$$$: $$$[5, 0, 0, 0, 1, 1]$$$
Day $$$5$$$: $$$[0, 0, 0, 0, 0, 0]$$$
Note that the last trust loss of $$$1$$$ does not actually matter at all.
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 9, Intermediate 8, Advanced 3
Timothy is the president of the triangle fan club, and they have decided to create a flag! The design they settled on was an isosceles right triangle. They want to cut it out from a $$$N \times M$$$ rectangular piece of cloth with the two legs of the triangle being parallel to the sides of the cloth. The orientation of the flag matters, one leg of the triangle must be on the bottom and the other must be on the right (more details are given in the notes).
Unfortunately, the cloth had been stored in the attic with moths, so there were holes all over it. Timothy wants to know how many places still exists on the cloth that he can a flag out of.
Timothy hasn't decided on the size of the flag yet, and he wants to explore all the possibilities. He asks you to find the number of different places he can cut a flag out of for each flag size from $$$2$$$ to $$$\min{(N, M)}$$$. A flag of size $$$X$$$ has legs of length $$$X$$$ each.
The first line contains $$$2$$$ integers, $$$N$$$ and $$$M$$$ $$$(1 \leq N, M \leq 1000)$$$, the number of rows and number of columns of the cloth.
The next $$$N$$$ lines contain $$$M$$$ characters each. The characters are either $$$.$$$ or $$$*$$$, with $$$.$$$ representing a hole in the cloth and $$$*$$$ representing that there isn't.
Print $$$\min{(N, M)} - 1$$$ lines. The $$$i$$$th line denotes the number of different spots Timothy is able to cut a flag of size $$$i + 1$$$ out of.
4 5 ..*.* ***** ***** *****
10 5 1
A valid flag of size $$$3$$$ looks like this: $$$$$$ \begin{matrix} . & . & *\\ . & * & *\\ * & * & * \end{matrix} $$$$$$ Other orientations of flags don't work, for example: $$$$$$ \begin{matrix} * & . & .\\ * & * & .\\ * & * & * \end{matrix} $$$$$$ is not a valid flag of size $$$3$$$.
Two flags are considered to be in different locations if they have any point that is different between them. They are allowed to overlap.
$$$---------------------------------$$$
Idea: Timothy
Preparation: Mantlemoose, Timothy
Occurrences: Novice 10, Intermediate 7
Thomas wants to game! But teacher is making him do some hard problems to stop him from gaming. In particular, teacher has forced Thomas to work on an $$$O(n)$$$ matrix mutliplication problem. Thomas currently has a matrix multiplication for two $$$n$$$ by $$$n$$$ matrices written as follows:
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
for(int k = 0; k<n; k++){
c[i][j] = c[i][j] + a[i][k]*b[k][j];
}
}
}
Thomas's code is not $$$O(n)$$$ and TLE's! However, Thomas has thought of a way to make his matrix multiplation $$$O(1)$$$. He decided to handwrite all the transitions of his $$$n^3$$$ matrix multiplication! In particular, for all pairs $$$i,j$$$ such that $$$0 \leq i, j \lt n$$$, Thomas writes:
c[i][j] = a[i][0]*b[0][j] + a[i][1]*b[1][j] + ... + a[i][n-1]*b[n-1][j];
Please note that in all these examples so far, $$$a$$$, $$$b$$$, and $$$c$$$ have all been placeholders for the actual variable names Thomas uses. In practice, Thomas actually uses much more productive variable names (probably...)!
So below is an "expanded" matrix multiplication of $$$2$$$x$$$2$$$ matrices m1 and m2 into ret.
ret[0][0] = m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0];
ret[1][0] = m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0];
ret[0][1] = m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1];
ret[1][1] = m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1];
So now Thomas asks you, if you are given the length of the names of the result matrix, left matrix, and right matrix, and their dimension $$$n$$$, what is the number of non-whitespace characters in the expanded form of that matrix multiplication. Note that new lines and spaces are ignored when Thomas says "no white spaces"; all other characters contribute to the answer.
You will answer $$$T$$$ testcases $$$(1 \leq T \leq 10^5)$$$.
Each testcase consists of $$$4$$$ integers, $$$a, l, r, n$$$ $$$(1 \leq a, l, r \leq 10^3), (1 \leq n \leq 10^9)$$$. $$$a$$$ denotes the length of the name of the resulting matrix, $$$l$$$ denotes the length of the name the left hand matrix, $$$r$$$ denotes the length of the name of the right hand matrix, and $$$n$$$ is the dimension of the matrix multiplied.
Note that there are no constraints on the sum of any of the input values specified above.
Test case 1 will consist of all $$$10^4$$$ ways to pick $$$a, l, r, n$$$ from the numbers $$$1 \cdots 10$$$.
Tests $$$2-3$$$ will satsify $$$(1 \leq T \leq 10, 1 \leq n \leq 1000)$$$.
Tests $$$4 - 6$$$ will satsify $$$(1 \leq T \leq 10, 1 \leq n \leq 10^5)$$$.
Tests $$$7 - 10$$$ will satsify $$$(1 \leq T \leq 10^5, 1 \leq n \leq 10^5)$$$.
There are no additional constraints for the remaining tests.
Output $$$T$$$ lines, each line containing one integer, the number of characters in the Thomas expanded matrix multiplication. Since this number may be very large, please find it modulo $$$10^9 + 7$$$.
3 1 1 1 2 1 2 3 4 3 3 6 6
160 1344 5328
2 366 366 336 336 1000 1000 1000 33663366
456345987 778866085
—
Idea: 3366
Preparation: 3366
Occurrences: Novice 8, Intermediate 6
This is the easy version. The difference between the easy version and the hard version is the constraints.
Misaka Imouto $$$1$$$, Misaka Imouto $$$2$$$, ..., and Misaka Imouto $$$n$$$ are all playing rock paper scissors to determine who should go buy the cake. Since they are all connected to the same network, let's assume that all Misaka Imouto's act the same.
A game of rock paper scissors is dictated as follows:
One possible game between $$$3$$$ Misaka Imouto's could be as follows: RPS, RRS, SSX, SRX, and ending with the second Misaka winning after $$$4$$$ rounds. In this game, R means rock, S means scissors, P means paper, and X means that this Misaka Imouto has lost already and was not allowed to play.
For each $$$i$$$ from $$$1$$$ to $$$n$$$, find the expected number of rounds a game with $$$i$$$ Misaka Imoutos initially lasts.
The input contains two numbers $$$n$$$ and $$$P$$$, $$$(2 \leq n \leq 10^4, 10^{8} \leq P \leq 10^{9})$$$. It is guaranteed that $$$P$$$ is a prime.
For tests $$$1 - 4$$$, $$$(2 \leq n \leq 50)$$$ will be satisfied.
For tests $$$5 - 8$$$, $$$(2 \leq n \leq 3366)$$$ will be satisfied.
The remaining test data do not satisfy any additional constraints.
Output $$$n$$$ integers, the $$$i$$$'th integer denoting the expected number of rounds a game with $$$i$$$ Misakas initially will last.
So for each $$$i$$$ from $$$1$$$ to $$$n$$$, let the final expected number of rounds of a game with $$$i$$$ Misaka Imoutos be $$$\frac{x_i}{y_i}$$$, output $$$z_i$$$ $$$(0 \leq z_i \lt P)$$$ where $$$x_i \equiv y_i \cdot z_i \pmod P$$$.
5 100000007
0 50000005 25000004 64285722 25714292
$$$50000005$$$ is also $$$\frac{3}{2} \mod 100000007$$$
$$$25000004$$$ is also $$$\frac{9}{4} \mod 100000007$$$
—
Idea: 3366
Preparation: 3366
Occurrences: Intermediate 10, Advanced 4
After seeing their rivalry, teacher has challenged Thomas and Waymo into the hardest team bonding activity eve. Rules are as follows:
If Thomas starts on node $$$t$$$ and Waymo starts on node $$$w$$$, what is the maximum number of coins they can obtain after any finite amount of moves?
You will have to answer multiple testcases. The first line contains an integer $$$T$$$, denoting the number of testcases $$$(1 \leq T \leq 10^4)$$$.
The first line of each testcase contains two integers $$$N$$$ and $$$M$$$, $$$(1 \leq N \leq 2 \cdot 10^5), (0 \leq M \leq 5 \cdot 10^5)$$$
The following line contains two integers $$$t$$$ and $$$w$$$ $$$(1 \leq t, w \leq N)$$$, denoting the nodes that Thomas and Waymo start on respectively.
The next $$$M$$$ lines each contain $$$3$$$ integers $$$u$$$, $$$v$$$, and $$$l$$$ $$$(1 \leq u \neq v, l, \leq N)$$$ denoting an edge connected nodes $$$u$$$ and $$$v$$$ with label $$$l$$$.
It is guaranteed the graph does not have any multiedges.
It is also guaranteed the sum of $$$N$$$ does not exceed $$$2 \cdot 10^5$$$ and the sum of $$$M$$$ does not exceed $$$5 \cdot 10^5$$$.
For tests $$$1 - 3$$$, $$$(1 \leq N \leq 16)$$$ and the sum of $$$N$$$ will not exceed $$$50$$$.
For tests $$$4 - 10$$$, the sum of $$$N$$$ will not exceed $$$3366$$$.
The remaining test cases do not satisfy any additional constraints.
For each testcase, output $$$1$$$ integer per line, the maximum number of coins Thomas and Waymo can collect by moving zero or more times.
2 5 5 1 2 1 2 2 3 2 1 1 3 2 2 4 4 4 5 5 5 5 4 5 1 2 2 3 2 1 1 3 2 2 4 4 4 5 5
3 2
In the first test case, Thomas can collect the coin on node $$$1$$$ and Waymo can collect the coin on node $$$2$$$. Then Thomas can move from node $$$1 \rightarrow 3$$$ and collect the coin on node $$$3$$$. It is impossible to collect any more coins, so the answer is $$$3$$$.
In the second test case, Thomas can collect the coin on node $$$4$$$ and Waymo can collect the coin on node $$$5$$$. Note that Thomas cannot move from node $$$4$$$ to node $$$2$$$, since Waymo is not on node $$$4$$$ to satisfy the $$$l = 4$$$ constraint. By the same logic, Waymo cannot move to node $$$4$$$. Thomas also has the choice to move to node $$$5$$$, but there is nothing gained from such a move. The final answer is $$$2$$$.
—
Idea: Timothy
Preparation: Timothy, 3366
Occurrences: Novice 11, Intermediate 9, Advanced 5
In his quest to become the better TA, Thomas suddenly received inspiration: "What if he tried to learn from someone who was already a teacher?". Thomas immediately thought of teacher and realized if he wanted to become a better TA, he had to be driving at all times. (Note that Thomas has tried biking as a greener method of transport, but that failed).
Thomas currently lives in a country with $$$N$$$ cities and $$$M$$$ roads between cities. Every road also has a parameter $$$t$$$, denoting the number of minutes to pass through a road.
Consider a road trip from some city $$$u$$$ to city $$$v$$$. Let us assume that Thomas has unlimited mileage from infinite money and the only thing limiting his drives is his patience. If Thomas's patience is $$$p$$$, he can only drive on roads that require $$$p$$$ minutes to drive through. For instance having patience $$$3$$$ can enable Thomas to travel through roads that take $$$1$$$, $$$2$$$, or $$$3$$$ minutes to cross.
Now Thomas has a list of cool cities that is initially empty but is always growing. He will make $$$Q$$$ additions to that list. After each addition, he asks what the minimum patience he needs to make a road trip between any two cool cities is. Note that Thomas is picking two cities and then traveling between them, not taking the answer over all pairs of cities.
The first line contains three integers $$$N$$$, $$$M$$$, $$$Q$$$ $$$(1 \leq Q \leq N \leq 10^5, 1 \leq M \leq 2 \cdot 10^5)$$$ denoting the number of cities, roads, and additions to the list respectively.
The following $$$M$$$ lines contain three integers each, $$$u$$$, $$$v$$$, $$$t$$$ $$$(1 \leq u \neq v \leq N, 1 \leq t \leq 10^9)$$$ the two cities this road connects as well as the number of minutes needed to traverse it. Note that the graph may have multiedges.
The following $$$Q$$$ lines each contain one integer, $$$x$$$ $$$(1 \leq x \leq N)$$$, the new city Thomas considers cool. It is guaranteed Thomas never adds the same city twice to his list.
For tests $$$1 - 3$$$, $$$(1 \leq Q \leq 10)$$$.
For tests $$$4 - 7$$$, $$$(1 \leq t \leq 2)$$$.
For tests $$$8 - 10$$$, $$$|u - v| = 1$$$ for all edges.
The remaining test cases do not satisfy any additional constraints.
Output $$$Q$$$ lines, each line containing one integer, denoting the minimum amount of patience needed to make a road trip between any two cool cities. Output $$$-1$$$ if it is impossible to make such a trip.
5 7 3 1 2 3 2 4 2 3 5 4 1 5 10 3 4 7 4 5 6 2 5 6 4 3 1
-1 6 3
After adding the first cool city, $$$4$$$, there is only 1 city so Thomas cannot make any trip.
After adding the second cool city, $$$3$$$, Thomas can make the trip $$$4 \rightarrow 5$$$, $$$5 \rightarrow 3$$$ only using patience $$$6$$$. Note that going from $$$4 \rightarrow 3$$$ would take patience $$$7$$$. Thomas can also reach cities $$$2$$$ and $$$3$$$ with $$$6$$$ patience, although there isn't much of a point in going there.
After adding the third cool city, $$$1$$$, Thomas can make the trip $$$4 \rightarrow 2$$$, $$$2 \rightarrow 1$$$ with patience $$$3$$$.
—
Idea: 3366
Preparation: 3366
Occurrences: Advanced 6
Codicon is traversing through an $$$N$$$x$$$N$$$ grid ($$$2 \leq N \leq 1000$$$). He starts at the top left cell and goes to the bottom right, where in each step he either moves one block down or one block right. Chessbot however, has a scheme and would like Codicon to traverse a specific path (for no nefarious reason of course). He will do this by strategically placing impassable rocks in certain spots (not at the start or end cell). But rocks cost a lot of money, so being the thrifty person he is Chessbot would like to use as little rocks as possible to make his path the only valid path Codicon can take. Find the minimum amount of rocks needed to do so.
A valid path is one where Codicon starts in the top left, ends in the bottom right, only moves right or down, and does not pass any rocks.
The first line has one integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) denoting the number of tests.
Each of $$$T$$$ tests has two lines. The first line contains only the integer $$$N$$$. The second line has a string of length $$$2 \cdot N - 2$$$ denoting the path Chessbot wants Codicon to take in the form of 'R's and 'D's, where 'R' signals he wants Codicon to go one block to the right and 'D' signals he wants Codicon to go one block down. The sum of $$$N^2$$$ across all tests is guaranteed to be less than or equal to $$$10^6$$$.
For each test case, a single integer denoting the minimum number of rocks needed to make the path Chessbot wants to be the only valid path.
2 6 RRDDRRRDDD 5 DDDRDRRR
7 5
For this explanation we'll use cartesian coordinates where the top left cell is $$$(1, 6)$$$. For the first case, note that if Chessbot places rocks in the cells $$$(1, 5)$$$, $$$(2, 5)$$$, $$$(3, 3)$$$, $$$(4, 2)$$$, $$$(4, 5)$$$, $$$(5, 3)$$$, $$$(5, 6)$$$ then Codicon must take the desired path. It can be proven that this is the least amount of rocks necessary to do so.
$$$-------------------------------------------------$$$
Idea: Bossologist
Preparation: Bossologist
Occurrences: Intermediate 12, Advanced 9
Timothy travels between lattice points on a coordinate plane, with $$$Y \in$$$ {$$$1,2...N$$$} and $$$X \in$$$ {$$$1,2...M$$$}. He can freely move up and down across Y coordinates, but cannot move freely left and right across X coordinates. However, there are $$$K$$$ roads available to him, each of which spans from $$$(x_a, y_r)$$$ to $$$(x_b, y_r)$$$ where $$$x_a \leq x_b$$$, and allows him to move freely between any points $$$(x_i, y_r)$$$ and $$$(x_j, y_r)$$$ where $$$x_a \leq x_i$$$, $$$x_j \leq x_b$$$. We have to answer $$$Q$$$ queries, each of which asks if it's possible to travel from $$$(A, B)$$$ to $$$(C, D)$$$, traveling only across $$$y$$$ coordinates between $$$min(B, D)$$$ and $$$max(B, D)$$$ inclusive (so he may use roads with y-coordinate $$$B$$$ or $$$D$$$).
The first line contains the integers $$$N$$$ ($$$1 \leq N \leq 10^9$$$), $$$M$$$ ($$$1 \leq M \leq 2 \cdot 10^5$$$), $$$K$$$ $$$(1 \leq K \leq 2 \cdot 10^5)$$$, and $$$Q$$$ ($$$1 \leq Q \leq 2\cdot 10^5$$$) respectively.
The next $$$K$$$ lines denote each of the roads with three integers $$$x_a$$$, $$$x_b$$$, and $$$y_r$$$ respectively ($$$1 \leq x_a \leq x_b \leq M$$$, $$$1 \leq y_r \leq N$$$).
The final $$$Q$$$ lines each denote a query with the integers $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$ ($$$B \neq D$$$, $$$1\leq A,C \leq M$$$, $$$1\leq B,D \leq N$$$).
Test cases 1-5: $$$N,$$$ $$$M,$$$ $$$K,$$$ $$$Q \leq 2000$$$
Test cases 6-20: No further restrictions
$$$Q$$$ lines of output where the $$$i$$$'th line is a "YES" if Timothy can reach his destination in the $$$i$$$'th query, and a "NO" if he cannot.
10 5 2 2 1 2 2 2 3 1 1 1 3 3 4 3 2 1
YES NO
On the first query note that Timothy can move up to $$$(1, 2)$$$, then take the first road to $$$(2, 2)$$$. Then he can move down to $$$(2, 1)$$$, use the second road to move to $$$(3, 1)$$$, and from there move up to his destination at $$$(3, 3)$$$. On the second query note that Timothy is only able to move up and down and therefore not able to make it from $$$(4, 3)$$$ to $$$(2, 1)$$$.
$$$-------------------------------------------------$$$
Idea: Timothy
Preparation: Timothy, Bossologist
Occurences: Advanced 7
1900 years ago, a colossal pit was discovered on an island. The abyss is 1000 meters in diameter and at least 20,000 meters deep — at least because none have reached the bottom. The allure of the Abyss is inescapable, so Riko has decided to embark on the adventure of a lifetime.
Riko's journey passes through $$$N$$$ locations numbered from $$$1$$$ to $$$N$$$. The distance between the $$$(i-1)$$$th and $$$i$$$th location is $$$A_i$$$.
Additionally, there are $$$M$$$ types of roads. The roads of the $$$k$$$th type are described with $$$3$$$ integers, $$$S_k$$$, $$$E_k$$$, $$$L_k$$$. For any $$$(i,j)$$$ such that $$$S_k \leq i \lt j \leq E_k$$$ and $$$abs(j-i) \leq L_k$$$, there is a road of the $$$k$$$th type from city $$$i$$$ to city $$$j$$$. Notice that $$$i \lt j$$$ because ascending causes horrific symptoms from the curse of the Abyss.
Furthermore, the cost of traversing the road from city $$$i$$$ to city $$$j$$$ is $$$(A_{i+1} \oplus A_{i+2} \oplus \dots \oplus A_j) - 16$$$ where $$$\oplus$$$ is the bitwise XOR operator.
A valid journey from city $$$1$$$ to $$$N$$$ satisfies that the types of the roads used are in $$$\textbf{strictly}$$$ increasing order. It is guaranteed that a valid journey exists.
Riko is an explorer, but she is not a programmer. So, Riko asks you to find the minimum cost for her to travel from city $$$1$$$ to city $$$N$$$.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^3)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first line of each test case contains $$$2$$$ integers, $$$N$$$ and $$$M$$$ ($$$3 \leq N \leq 10^5$$$, $$$2 \leq M \leq 20$$$).
The second line of each test case contains $$$N-1$$$ integers: $$$A_2, A_3, \dots, A_N$$$ ($$$0 \leq A_i \leq 2^5-1$$$).
The last $$$M$$$ lines describe the roads. The $$$k$$$th of which contains $$$3$$$ integers, $$$S_k$$$, $$$E_k$$$, $$$L_k$$$ ($$$1 \leq S_k \lt E_k \leq N$$$, $$$1 \leq L_k \leq E_k-S_k$$$).
Tests $$$1-2$$$ will satisfy that the sum of $$$N^2$$$ over all test cases does not exceed $$$10^5$$$.
Tests $$$3-20$$$, the remaining tests, will satisfy that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.
For each testcase, output the minimum cost for Riko to travel from city $$$1$$$ to city $$$N$$$.
1 4 2 1 1 2 1 3 2 1 4 2
-30
For the first and only test case of the example, there are $$$2$$$ possible ways to get from city $$$1$$$ to city $$$4$$$.
The first way: Take a road of type $$$1$$$ from city $$$1$$$ to city $$$2$$$, which costs $$$1 -16 = -15$$$. Then, take a road of type $$$2$$$ from city $$$2$$$ to city $$$4$$$, which costs $$$(1 \oplus 2) -16 = -13$$$. The total cost is $$$-15 + (-13) = -28$$$.
The second way: Take a road of type $$$1$$$ from city $$$1$$$ to city $$$3$$$, which costs $$$(1 \oplus 1) -16 = -16$$$. Then, take a road of type $$$2$$$ from city $$$3$$$ to city $$$4$$$, which costs $$$2 -16 = -14$$$. The total cost is $$$-16 + (-14) = -30$$$.
Thus, the minimum cost is $$$-30$$$.
$$$---------------------------------$$$
Idea: Codicon
Preparation: Codicon
Occurrences: Intermediate 11, Advanced 8
There used to exist a good story about someone getting food poisoning from eating at restaurants. It is now replaced by a cleaner statement.
You have an integer $$$N$$$ and a set of primes that initially contains the first $$$M$$$ primes. You have to handle $$$Q$$$ queries, where for each query, you make a modification to the set of primes. You either insert a prime that is not present in the set already or delete a prime that is already present in the set. After each query, you have to output the number of numbers $$$x$$$ $$$(1 \leq x \leq N)$$$ such that $$$x$$$ is divisible by at least one prime in the set. All operations will only consist of the first $$$M$$$ primes.
The first line of input contains $$$3$$$ integers $$$N$$$, $$$M$$$, $$$Q$$$ $$$(1 \leq N \leq 10^6, 1 \leq M \leq N, 1 \leq Q \leq 10^5)$$$, the number of numbers to maintain in the queries, the number of primes that are set initially, and the number of modifications initially. It is guaranteed the $$$M$$$'th prime number is not greater than $$$N$$$.
The following $$$Q$$$ lines contain one integer each, $$$x$$$, denoting the prime to be updated, meaning that you are either inserting the $$$x$$$'th prime or deleting the $$$x$$$'th prime. If the $$$x$$$'th prime is already present, you will remove it from the set. Otherwise, the $$$x$$$'th prime is not present, and you are inserting it into the set.
For testcases $$$1$$$ - $$$2$$$, $$$(1 \leq N, Q, \leq 10^3)$$$.
For testcases $$$3$$$ - $$$4$$$, each element is only queried at most once.
For testcases $$$5$$$ - $$$6$$$, $$$(1 \leq M \leq 10)$$$.
For testcases $$$7$$$ - $$$10$$$, $$$(1 \leq n \leq 10^4)$$$.
There are no additional constraints on the remaining testcases.
Output $$$Q$$$ lines, one integer each, the $$$i$$$'th line denoting the number of primes that are divisible by at least one prime in the set after the $$$i$$$'th update.
Note that the number $$$1$$$ will never be divisible by any primes in the set.
10 4 7 1 2 1 2 3 1 4
6 3 7 9 8 4 3
$$$p_1 = 2 \\ p_2 = 3 \\ p_3 = 5 \\ p_4 = 7$$$
Let $$$S$$$ denote the elements from $$$1 \cdots 10$$$ that are divisible by at least one prime in the set.
After the first query, $$$S$$$ is $$$[3, 5, 6, 7, 9, 10]$$$.
After the second query, $$$S$$$ is $$$[5, 7, 10]$$$.
After the third query, $$$S$$$ is $$$[2, 4, 5, 6, 7, 8, 10]$$$.
After the fourth query, $$$S$$$ is all the numbers from $$$1 \cdots 10$$$ aside from the number $$$1$$$.
After the fifth query, $$$S$$$ is all the numbers from $$$1 \cdots 10$$$ aside from numbers $$$1$$$ and $$$5$$$.
After the sixth query, $$$S$$$ is $$$[3, 6, 7, 9]$$$.
After the last query, $$$S$$$ is $$$[3, 6, 9]$$$.
—
Idea: Everule, 3366
Preparation: 3366
Occurrences: Advanced 10
This is the hard version. The difference between the easy and the hard versions is that the hard version has higher constraints.
Misaka Imouto $$$1$$$, Misaka Imouto $$$2$$$, ..., and Misaka Imouto $$$n$$$ are all playing rock paper scissors to determine who should go buy the cake. Since they are all connected to the same network, let's assume that all Misaka Imouto's act the same.
A game of rock paper scissors is dictated as follows:
One possible game between $$$3$$$ Misaka Imouto's could be as follows: RPS, RRS, SSX, SRX, and ending with the second Misaka winning after $$$4$$$ rounds. In this game, R means rock, S means scissors, P means paper, and X means that this Misaka Imouto has lost already and was not allowed to play.
For each $$$i$$$ from $$$1$$$ to $$$n$$$, find the expected number of rounds a game with $$$i$$$ Misaka Imoutos initially lasts.
The input contains two numbers $$$n$$$ and $$$P$$$, $$$(2 \leq n \leq 10^5, 10^{8} \leq P \leq 10^{9})$$$. It is guaranteed that $$$P$$$ is a prime.
Output $$$n$$$ integers, the $$$i$$$'th integer denoting the expected number of rounds a game with $$$i$$$ Misakas initially will last.
So for each $$$i$$$ from $$$1$$$ to $$$n$$$, let the final expected number of rounds of a game with $$$i$$$ Misaka Imoutos be $$$\frac{x_i}{y_i}$$$, output $$$z_i$$$ $$$(0 \leq z_i \lt P)$$$ where $$$x_i \equiv y_i \cdot z_i \pmod P$$$.
5 100000007
0 50000005 25000004 64285722 25714292
$$$50000005$$$ is also $$$\frac{3}{2} \mod 100000007$$$
$$$25000004$$$ is also $$$\frac{9}{4} \mod 100000007$$$
—
Idea: 3366
Preparation: 3366
Occurrences: Advanced 11