The round consists of 6 problems and you will have two hours to solve them.

The problems were prepared by me with great help from linkinu and 1am. I would like to thank KAN for his great efforts in reviewing the problems and for his suggestions, it is really amazing to see the work done behind every round. Also thanks to Tommyr7, Livace and mike_live for testing the problems, and to arsor for translating the statements into Russian.

This is my first round on Codeforces, I hope that you will find some interesting problems for you.

1- Every pair of integers that are not 0 will be part of the same group if and only if the set of primes with odd exponent is the same for both numbers (when you write numbers as a product of prime numbers)

2- Every 0 can be part of any group.

Then you can pre-group the numbers and after that you just calculate the answer for every subarray.

You can think of it as "keeping" vertices. So first you keep vertex n, then you try to keep vertex n-1, then n-2 etc. (To keep a vertex i, you need to keep every vertex on the path from n to i)

We realize that we keep at most n vertices. Thus, every time we keep a vertex, we can mark it as kept. Now we want to know the first ancestor of vertex i that is already kept (this tells us how many more vertices we need to keep along the way in order to keep vertex i).

We can use parent doubling to check this in O(lg N), so I don't see why we need O(1) LCA here.

I solved it as follows: given a tree T and a vertex u, we have to find the vertex v in T that maximizes the depth of lca(u,v). Note that a solution for v is one of the leafs that is next to u (left or right) in dfs-order. Mine is also Nlog(N), so I was surprised when I got TLE

meeeep Can u give any link to learn about the "parent doubling" that u used? One more thing why cant we proceed in this way:- remove the smallest weight leaf from the tree and repeat the same on the new tree until we remove k nodes which could be seen as minimizing the number of fans that we lose by removing a node?

I don't know a link, but it should be pretty simple to explain (hopefully).

For each node, you store your 2^i-th parent for each integer i. (A convenient initialization for this question is that the parent of the root is itself).

We initialize the 2^0-th (i.e. direct parent) manually. For each i>1, we notice that the 2^i-th parent is just the 2^(i-1)-th parent of the 2^(i-1)-th parent, so we may find this is constant time... assuming we have already computed the parents of its 2^(i-1)-th parent. This means that we want to compute parents in some kind of pre-order DFS, which can be written together with the DFS that roots the tree.

, process the cities from greatest to least and greedily take them. First, root the tree at the largest value (you always take it). Then to see if you can take city $x$, see how many cities you haven't taken that are on the path from x to the root. If you can take all of them, do so, otherwise ignore this city.

You see: it's not about how YOU see the problem. It's about how does others see it. For you it may be obvious that it can be zero pearls. For me too. But it can be not obvious for others, and that's ok, all people are different and have different points of view. What's why you need to specify such things as constraints, so it will be obvious for anyone.

2nd and 3rd cases can be understood as inversions of each other. Look at soham_1234's examples: inner matrix of 2nd case is inverse of inner matrix of the 3rd case. So if we have k ≥ n - 2, then we can assign k to (n - 2) * 2 - k and make inversion after (perl code — 38050716).

Consider the test case [5 2 8]. There are 6 sub arrays. For each, we want to separate it into as few groups such that product any pair of elements in any group is a perfect square. For this example, the groups are

[5 2 8] -> (5) (2 8)

[5 2] -> (5) (2)

[2 8] -> (2 8)

[5] -> (5)

[2] -> (2)

[8] -> (8)

Now, since 4 of them sep into 1 group, and 2 sep into 2 groups, the ans is

Yes C was ofcourse easy. B was harder than C because there were 3 independent cases to tackle and needed good observation or otherwise tricks like generating no of paths for smaller datasets and observing patterns

I disagree. My thought process was just "you can reverse the ending/start so it's just number of paths between the diagonals. If the grid is symmetric then the answer is the same". For problem C I struggled to understand what it asked until looking at the samples.

When writing code for problem A, I know that I have to wait for the statement update to handle the case of 0 pearls. I took me few more minutes. I don't know how 1500 solvers before me manage this case.

if k is even: We put 2 #'s in grid[1] and grid[2] as long as needed. Why this works? Well see symmetry with respect to (1,1) and (4,1) one can easily tell that no of paths will be same. ..... .#... .#... .....

Problem B Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond? But they are counting all paths.Please,be more clear about the problem statement. Thank you

The problem is correctly asking for shortest paths. Remember this is distance in taxicab geometry, so in a 4*n grid, going from (1,1) to (4,n) takes 3+n-1 steps regardless you take the "inverted-L-shaped" path or some intermediate "staircase-shaped" path. This is true for any path that does not go back to the starting point. This is the same for (4,1) to (1,n).

For my reasoning, the key was observing how the two "diagonal" paths (that are shortest paths too!) crossed => place hotels with horizontal symmetry.

Well it's easy to see that if you set hotels symmetrically equal to each other, the tourists will always have the same number of paths. The worst case is to set hotels is such a way like

.......
.#####.
.#.....
.......

at this point, there will be no equal number of paths because you block the shortest way to upper guys and lower ones have no problem to pass. But it doesn't give the "NO" answer, because you can just set that one hotel in the middle of second line since they made us sure, number of columns will always be odd.

So there is no option to get wrong answer, you can just do:

fullfill lines if number of hotels is bigger than n — 2 and for modulo number of hotels left from k / (n — 2) (the rest of them) set simmetrically like 1st column -> last column -> 1st column -> last column.. with one condition, if your modulo equals 1 (so there is only 1 hotel to be set) just place it in the middle of the line

In other words always go like -> middle -> left -> right -> left -> right...

Aah, now they make sense to me. Your first example made it pretty clear and the middle->left->right... seems to be the way to go. Thanks a lot! I coded it in a similar fashion and got an AC. Great explanation! Here is my code: 38055986

To keep or remove the same number of "diagonal" paths from both sources, you have to place hotels with horizontal symmetry, leaving a hole in the middle column if they are even, or putting one in the middle column too, if they are odd.

See for example the (now fixed) drawing in my comment above. The crossing diagonal paths form a shape resembling an X, while path on the borders are L-shaped. Imagine to morph between the two to find other possible paths.

If there are no hotels, for any path from top-left to bottom-right you can find a mirrored path from bottom-left to top-right. For any top-left path you remove, you want to remove the corresponding bottom-left path.

For example, to remove the two diagonal like paths you can place two hotels like this:

For those who are curious how the color distributions are changed due to the update of upper bound of the rating on "Div.2 Only" rounds. Please be informed that this describes top 2000 contestants for each round:

Hey good job. Can you brief in 1-2 lines rhat what can we conclude from.this data? Seems to me like it says more about the level of the specific rounds rather than the updated rating system. Please enlighten me :)

If I understand your question, I believe Codeforces #480 was the first "Div. 2 Only Round" that contestants in purple participated. In other words, purple lines described here hadn't appeared in any previous rounds! :)

We add bidirectional edges between pair of nodes i to j if ai·aj is a perfect square. My first observation was, every connected component is a complete graph. Let, bi be the binary string consisting the parity of powers of primes of ai. Then if i and j are connected and j and k are connected, then i and k are also connected. Because, i and j connected means — (1), again, j and k connected means — (2). Combining (1) and (2), we get , means i and k have an edge. This gives us enough material to prove that all connected components are complete graph.

Now, the problem reduces to finding the number of connected component of the sub-graph consisting only edges in a range, i.e. in [l;r](1 ≤ l ≤ r ≤ n).

To do this, I implemented this using the following way:

We first select sub-array's starting point, let's say i(actually we also iterate this from left to right), then iterate on the ending point from left to right (denote it also with j). When extending one node to the right (means, we are going from j to j + 1) we need to only know if j + 1 connects to any of the node in range [i, j]. If it does, then number of connected component remains same, increases by 1 otherwise. As we don't care about the edges connecting with a node left to i, we may delete them on the go i.e. when we move the left end point one step right, i to i + 1, we delete all the edges that are connecting node i and another node with index greater than i. Another observation is that, when we are trying to find if the new node j + 1 can be connected with any component, we need not to check all the edges as all the edges lead to the same component. Instead of keeping all the edges we will keep the edge which connects j + 1 with the closest node left to j + 1. More formally-

For each i(1 ≤ i ≤ n), maximum j < i such that there is an edge between i and j, if there is none then it's simply - 1. Again a set for each i, .