In the wonderful mountain ranges of the United States of Berland there are $$$n$$$ peaks. Each peak is characterized by 3 integers: $$$h$$$, $$$l$$$ and $$$r$$$. Peak $$$i$$$ is currently $$$h_i$$$ meters tall and its height can vary within a year by any integer $$$\Delta h \in [l_i,r_i]$$$.
Formally, if at the start of year $$$k$$$ the height of peak $$$i$$$ was $$$h_k$$$, at the end of that year the height of peak $$$i$$$ can be any integer in the interval $$$[h_k+l_i,h_k+r_i]$$$. It is possible for some peaks to reach negative heights (aka become sinkholes) after some time.
For each mountain $$$i$$$ you are given $$$h_i$$$, $$$l_i$$$ and $$$r_i$$$. Find the maximum possible number of peaks with equal heights at the beginning of year $$$y$$$ and the number of distinct heights reachable by this maximum number of peaks.
The first line of input contains two integers $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$, the number of peaks and $$$y$$$ $$$(0 \le y \le 10^9)$$$, the number of years. Each of the next $$$n$$$ lines of input contain 3 integers $$$h_i,l_i$$$ and $$$r_i$$$, describing the peaks $$$(-10^9 \le l_i \le r_i \le 10^9$$$ and $$$1 \le h_i \le 10^9)$$$.
Print two integers, the maximum number of peaks that can reach the same height after $$$y$$$ years, and the number of distinct heights that can be reached by the maximum number of peaks.
3 2 3000 -250 600 4000 0 50 5000 -500 250
3 101
5 1 1000 0 1000 3000 -1000 0 5000 0 1000 7000 -1000 0 9000 -9000 0
3 2
7 0 2000 -1000 1000 1000 -1000 1000 3000 -1000 1000 1000 -1000 1000 4000 -1000 1000 2000 -1000 1000 3000 -1000 1000
2 3
şi nu ucid
cu mintea tainele, ce le-ntâlnesc
în calea mea
în flori, în ochi, pe buze ori morminte.
Lumina altora
sugrumă vraja nepătrunsului ascuns
în adâncimi de întuneric,
dar eu,
eu cu lumina mea sporesc a lumii taină -
şi-ntocmai cum cu razele ei albe luna
nu micşorează, ci tremurătoare
măreşte şi mai tare taina nopţii,
aşa îmbogăţesc şi eu întunecata zare
cu largi fiori de sfânt mister
şi tot ce-i neînţeles
se schimbă-n neînţelesuri şi mai mari
sub ochii mei-
căci eu iubesc
şi flori şi ochi şi buze şi morminte.
Recently, the International Olympiad in Antigo has been announce to be held this year, and Aznurf has begun training for it. Antigo is a game similar to Go, only that it is played on a finite rectangular surface on an infinite table. For simplicity, the entire table is an xOy cartezian plane, and before each round, the players are announced that they will play with the points in the rectangular area between lower-left corner $$$(x1,y1)$$$ and upper-right $$$(x2,y2)$$$ (i.e. any point defined by $$$(x,y)$$$ such that $$$x1 \le x \le x2$$$ and $$$y1 \le y \le y2$$$ will be considered inside the area). With few fays before the championship, Aznurf found the key to the perfect opening move: any point defined by $$$(A,B)$$$ is given a value, which is either 1 if the point is "valorous" or 0 otherwise. If F(A,B) is the value of this point, then:
$$$F(A,B) = \left\{ \begin{array}{ c l } 1 & \quad \textrm{if } A=0 \textrm{ and } B=0 \\ F(A/5,B/5) & \quad \textrm{if } (A \textrm{ mod } 5) \textrm{ mod } 3 = (B \textrm{ mod } 5) \textrm{ mod } 3 \\ 0 & \quad \textrm{otherwise} \end{array} \right.$$$
One can reconsider this process as if both numbers are first converted to base 5, then after putting one above the other, each pair of corresponding digits are congruent modulo 3. Such an example of a point with value 1 would be (11206,1399), because $$$11206=324311_{(5)}, 1399=021044_{(5)}$$$ and $$$3 \equiv 0, 2 \equiv 2, 4 \equiv 1, 3 \equiv 0, 1 \equiv 4, 1 \equiv 4$$$
An hour before the contest, Aznurf gave into pressure saying "I want to start playing some game that is at least respected, like chess" , so now you're the only one in the national team.
After the competition, you made a fool of yourself. You're now curios in how many ways for each game in how many ways you could've opened the game, respecting the rules of Aznurf.
On the first line you have Q, the number of areas you have. Then, on each of the following Q lines, you are given $$$x1_{i},y1_{i},x2_{i},y2_{i}$$$, representing the i-th query
For each query, print the sum of the values of the points inside the respective rectangle
Restrictions:
$$$1\le Q \le 1\,000$$$
$$$1 \le x1 \le x2 \le 10^{18}$$$
$$$1 \le y1 \le y2 \le 10^{18}$$$
Additionally:
3 1 1 5 5 1 3 4 6 365 100 425 178
7 3 81
For the first game, we have the points with value 1: $$$(1,1), (2,2), (3,3), (4,4), (5,5), (1,4)$$$ and $$$(4,1)$$$
For the second game, we have the points with value 1: $$$(3,3), (4,4)$$$ and $$$(1,4)$$$
For the third game, we have a lot of points with value 1, so we ask you to believe us.
After creating $$$10^6$$$ boring problems , Le GrandPaPà decided to create a new one.
Your friend from Strehaia , Le GrandPaPà , once had a set $$$A$$$ of $$$N$$$ positive integers , but had unfortunately lost it. He only knows some properties of the array : It certainly contained $$$K$$$ pairs $$$(i,j)$$$ $$$1 \le i \lt j \le \lfloor \frac{N}{2} \rfloor$$$ satisfying the following property : $$$$$$A_{i+j} + A_{j-i} = \lfloor \frac{A_{2i} + A_{2j}}{2} \rfloor$$$$$$ Where $$$\lfloor X \rfloor$$$ denotes the biggest integer smaller or equal to $$$X$$$. GrandPaPà gives you integers $$$N,K$$$ and the $$$K$$$ pairs and asks you to find a set that could have been the one he lost.
The input consits of integers $$$N,K$$$ , followed by $$$K$$$ lines denoting the pairs $$$(i,j)$$$. $$$N,K \le 1000$$$
The output consists of $$$N$$$ integers , a set that could be the one GrandPaPà lost. All printed integers must be in range $$$[0,10^9]$$$ , and all must be distinct. Print -1 if there is no solution.
This problem allows partial scoring.
Let T be the number of pairs that satisfy the propriety. The score is given by the following formula :
4 1 1 2
7 4 1 12
The output is correct since $$$A_{1+2} + A_{2-1} = \lfloor \frac{A_{1 \cdot 2} + A_{2 \cdot 2}}{2} \rfloor$$$ $$$\Leftrightarrow$$$ $$$A_3 + A_1 = \lfloor \frac{A_2 + A_4}{2} \rfloor$$$ $$$\Leftrightarrow$$$ $$$1+7 = \lfloor \frac{16}{2} \rfloor$$$ $$$\Leftrightarrow$$$ $$$8 = 8$$$ which is true.
You can find information about Strehaia $$$\href{https://en.wikipedia.org/wiki/Strehaia}{here}$$$
You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$.
You are also given $$$q$$$ queries. Each query consists of two integers: $$$p$$$ ($$$1 \le p \le n $$$) and $$$x$$$ ($$$1 \le x \le 10^9$$$), meaning that $$$a_p$$$ will be replaced by $$$x$$$. For example, if $$$a=[6,5,5,3,6]$$$, $$$p=5$$$ and $$$x=7$$$, after the query $$$a$$$ will be equal to $$$[6,5,5,3,7]$$$.
After each query, print the number of inversions in array $$$a$$$. An inversion is a pair of indices $$$(i,j)$$$ where $$$i \lt j$$$ and $$$a_i \gt a_j$$$.
The first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5$$$ and $$$1 \le q \le 10^5$$$). The second line of input contains $$$n$$$ integers $$$1 \le a_1,a_2,\ldots,a_n \le 10^9$$$, the elements of the initial array. Each of the next $$$q$$$ lines contains two integers $$$p$$$ and $$$x$$$ ($$$1 \le p \le n$$$, $$$1 \le x \le 10^9$$$), the descriptions of the queries.
Print $$$q$$$ integers, the number of inversions after each query.
5 4 6 5 5 3 6 5 7 1 10 2 3 3 8
5 6 5 6
The Rubik's cube is a 3-D combination puzzle created by Hungarian sculptor and proffesor of architecture Erno Rubik. On the original classic Rubik's Cube, each of the six faces was covered by nine stickers, each of one of six solid colours: white, red, blue, orange, green, and yellow. In models as of 1988, white is opposite yellow, blue is opposite green, and orange is opposite red. - excerpt from Wikipedia
You are given a string $$$s$$$ of $$$n$$$ characters $$$s_i \in \{W, R, B, O, G, Y\}$$$. Each of these 6 letters coresponds to a colour featured on the Rubik's Cube (White, Red, Blue, Orange, Green and Yellow, respectively).
$$$s$$$ is considered a Rubik String if, for all adjacent characters, their coresponding colours are adjacent faces of the Rubik's Cube. For example, $$$"WRBOGY"$$$ is a Rubik String, while $$$"WW"$$$ and $$$"WYO"$$$ are not.
Naturally, not all strings are Rubik Strings, but they can be transformed into one via a sequence of (hopefully harmless) operations. In one operation, one can turn any character in $$$s$$$ into any other character $$$c_2 \in \{W, R, B, O, G, Y\}$$$.
For a given string $$$s$$$, find the minimum amount of operations required to make $$$s$$$ a Rubik String.
Each test contains multiple testcases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The following lines will contain the descriptions of the test cases.
The description of each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of string $$$s$$$.
The second line contains $$$n$$$ characters — the elements of string $$$s$$$.
It is guaranteed that the sum of $$$n$$$ will not exceed $$$5 \cdot 10^5$$$.
For each testcase print one integer — the minimum amount of operations required to turn $$$s$$$ into a Rubik String.
5 7 WWWWWWW 6 WRBOGY 2 WW 3 WYO 10 WYYWWBGROB
3 0 1 1 4
GrandPaPà gives you an array $$$A$$$ of $$$N$$$ elements. Your task is to split this array into $$$K$$$ non-intersecting non-empty contiguous subarrays such that the sum of all subarrays costs is minimum. The cost of an array $$$V$$$ is the number of pairs of indices $$$(i,j)$$$ such that i<j and $$$V_i \gt V_j.$$$
Input consists of numbers $$$N,K$$$ and an array $$$A$$$ of $$$N$$$ elements.
Print one integer : The minimum cost you can have.
4 2 4 3 2 1
2
The optimal split is [4,3][2,1]. The cost of this split is $$$1+1=2$$$ , which is minimum possible.
After getting money from the bank, Glob and Madf started their adventure. They have come across the Xor Plains, right below the Frozen Mountains.
The Plains can be represented as an array of $$$n$$$ distinct integers, where each element represents the height of the plains in that area. Let this array be called the 'plains array'. Glob knows that the bitwise xor of all heights is equal to $$$0$$$ and that the plains array is lexicographically minimal among all arrays whose xor-sum is $$$0$$$.
Glob has asked Madf to find the plains array, since he is too busy being the hero and gazing into the sunset. Madf succeeded, but can you?
The first line of input contains one integer $$$k$$$ ($$$1 \le k \lt 1500$$$), the number of testcases. The second line of input contains $$$k$$$ space separated integers $$$n_i$$$ ($$$3 \le n_i \le 2 \cdot 10^5$$$), the sizes of the plains arrays. It is guaranteed that the sum of $$$n$$$ across all testcases does not exceed $$$10^6$$$ (i.e. $$$\sum{n} \le 10^6$$$).
For each testcase, print $$$n_i$$$ distinct numbers from the interval $$$[1,10^6]$$$, representing the plains arrays.
3 3 5 6
1 2 3 1 2 4 8 15 1 2 3 4 8 12
These are the lexicographically minimal arrays whose xorsum is 0.
De te-ndeamnă, de te cheamă;
Ce e val, ca valul trece,
Nu spera și nu ai teamă;
Te întreabă și socoate
Ce e rău și ce e bine;
Toate-s vechi și nouă toate:
Vreme trece, vreme vine.
Reminiscing sadly on the prispă, El Capoc remembers the autumn. And with the autumn, he remembers a problem that made him very sad at the time:
Given a tree (undirected acyclic graph), rooted in node 1; Let p[u] be the parent of u (i.e. if we were to list the nodes on the path from the root to u, then the second-to-last element would be considered the father of u). Consider that p[1]=1.
Tolerate the following operations:
Update: Given u, the edge between $$$(p[u],u)$$$ is erased and $$$(p[p[u]],u)$$$ is inserted (i.e. the parent of leaf $$$u$$$ becomes $$$p[p[u]]$$$)
Query: Given u, Determine the maximum distance from u to one of the leaves in it's subtree (i.e. it's height)
On the first line of input, you are given $$$N$$$ and $$$Q$$$ ($$$1 \le N \le 90\,000$$$, $$$1 \le Q \le 190\, 000$$$), the number of nodes, respectively the number of operations. Then, on the following line, $$$N-1$$$ numbers follow, the i-th of with represents $$$p[i+1]$$$. Then, $$$Q$$$ lines follow, on each of these there will be two numbers: $$$t_i$$$ and $$$u_i$$$. If $$$t_i = 1$$$, then you must update the leaf $$$u_i$$$. Otherwise ($$$t_i = 2$$$), print the answer for the query with parameter $$$u_i$$$
For each query, print the respective distance
12 18 1 1 1 4 5 6 6 3 2 2 2 1 8 1 8 1 8 2 4 1 7 1 7 1 7 2 4 1 9 1 10 1 11 1 12 2 3 2 2 1 6 2 4 1 5 2 4
3 2 0 0 1 1
You can find the more clear and animated version of this at https://ibb.co/NW2fwD6 Also, we're terribly sorry for the weird restrictions.