### Vovuh's blog

By Vovuh, history, 16 months ago, , 961A - Tetris

Editorial
Solution (Vovuh)

961B - Lecture Sleep

Editorial
Solution (Vovuh)

961C - Chessboard

Editorial
Solution (Ajosteen)

961D - Pair Of Lines

Editorial

961E - Tufurama

Editorial
Solution (Ajosteen)

961F - k-substrings

Editorial
Alternative solution (jtnydv25)

961G - Partitions

Editorial   Comments (46)
 » 16 months ago, # | ← Rev. 2 →   Damn, I used Order Statistics tree to solve Problem E after the contest, and now I find it can be done with BIT.http://codeforces.com/contest/961/submission/36984273
•  » » Can you explain your approach ?
 » nice problemset :)Had solved E in 3 hours by using persistence segment tree. By seeing the editorial i think that i know nothing :)Nice editorial!
•  » » I solved E with persistence segment tree too, but it didn't took too much time because the only difference between normal segment tree and persistence segment tree is that you have to change the update process of later.
 » It's beautiful problemset, thx!
 » Geomety always seems to get me..
 » Can someone give me more detailed explanation of question B?
•  » » 15 months ago, # ^ | ← Rev. 2 →   First, in O(N) time, we can calculate "total", the current total number of theorems that Mishka will be able to write without the secret technique.Now we calculate the EXTRA number of theorems (apart from the ones for which Mishka needs no help) that Mishka will be able to write if the secret technique will get used at the first minute; this is O(K) of course. Call this number "cumu". Now in O(1) time, we can find out the number of theorems that Mishka can write down if the secret technique will get used at the second minute (just remove the number of theorems for the first minute (if applicable) and add the number of theorems for the (K+1)th minute (if applicable)). Keep "sliding" till you reach the end. Of course, maintain a maximum of what you have seen so far, which we call maxcumu.Finally, add "maxcumu" to "total". http://codeforces.com/contest/961/submission/36992860
 » I used just the priority queue and AVL for E and it just worked fine. In min priority queue I save pair of (ai,i). On reaching i+1 I pop all those ai from priority queue where aj
•  » » I have made the same, but with Fenwick tree (BIT), much more simple to code.
 » Nice F
 » Amazing problemset. I solved E after the contest using merge sort tree, it was pretty intuitive, and good oportunity to learn to code merge sort tree (because i didnt implement it before, only knew idea). Anyone else solved it this way?
•  » » Yah ! I also sloved it using merge sort tree.
 » Can anyone help me in understanding Problem E?
•  » » 15 months ago, # ^ | ← Rev. 2 →   Observe that for some season i we'll only get a collision with an episode of season j where j < i if aj >= i and ai >= j. So we just need to able to answer for a particular season i how many seasons with index j such that j < i have aj >= i and ai >= j. We can do this query for all i (using a merge-sort tree for example) and then report the answer.
 » 16 months ago, # | ← Rev. 2 →   For E, just use BIT to maintain sorted segments. Then use binary search (lower_bound in C++) to get the answer in each segment. I think it's the most simplest approach (or the best answer especially in a time highly limited competition).Here is my code 36971807Most of the shortest answers are done by this way.
•  » » Could you elaborate on your method? Looks interesting
•  » » » 16 months ago, # ^ | ← Rev. 2 →   Well. In this problem, we need to calculate how many numbers are greater than i in the range [i + 1, a[i]].Let d[l, r, x] denote how many numbers are greater than x in the range [l, r].Obviously, d[l, r, x] = d[1, r, x]-d[1, l-1, x] (prefix sums)Then you can use Binary Indexed Tree (BIT) with vector, which means each node of the BIT is a vector that collects numbers in a range, just like the node of a typical BIT sums numbers in the range.After sorting each vector, you can use binary search to get answers in each vector. By using BIT query method, you can form prefix sums and get d[l, r, x].
•  » » » » What will be the complexity of this solution? Like if You sort vectors in every node of BIT? Won't it be too much? Further, what will be the max size of a any vector representing a node?
•  » » » » » 15 months ago, # ^ | ← Rev. 2 →   Each number appears in O(log n) vectors. So the space complexity is O(n log n). Time complexity is O(n log^2 n).Well, the max size of a vector is O(n). However, the average size of vectors is just O(log n).
•  » » » » » » thanx a lot for sharing this approach!
•  » » » » » » Such an elegant and simple solution. Thanks.
 » For problem D what would be the approach if maximum number of lines allowed were 3?
•  » » 15 months ago, # ^ | ← Rev. 3 →   This is one thing I could think of; I am sure we can do better. Assume n >= 4, and assume that the n points lie on 3 lines. Consider any four points (say, the first ten points given). By Pigeonhole Principle, some 2 points lie on the same line. And well, take all cases. Once you are done finding one of the lines, the problem reduces to the given problem.Another less "casework" way considers n>= 10. Consider the first 10 points. Again by Pigeonhole Principle, some 4 points lie on the same line, and (I guess) we can also prove that if four points are collinear, then one of the lines must pass through them. So just find a quadruple of points that are collinear. If there does not exist a quadruple, then our assumption is false, otherwise the quadruple determines one line, and the problem has been reduced to D.
•  » » Another solution which can be easily generalized for more than two lines is: pick two different points at random, remove them and all points collinear with them and repeat until you have drawn expected number lines, and repeat the whole process until you have found way to partition all of the points or until clock() < TIME_LIMIT * CLOCKS_PER_SEC. Suppose pn points lie on first line and qn on the second (p + q) = 1 then probability of choosing points lying on the same line is roughly p2 + q2 which is greater or equal to ). In case of 3 lines we have at least chance for our first guess and at least for our second guess. which is total (or for k lines ). For k ≤ 5 this should be enough.
•  » » » 15 months ago, # ^ | ← Rev. 2 →   But the random can be hacked in open hacking……like 36960802
•  » » » » It can't be if I seed random number generator with the hash of the input. Or at least hacking it would be much more difficult.
 » Can someone explain me the question D ?
 » Can anyone help me in understanding Problem c?i am not getting tutorial too.
•  » » We have 4 pieces of board so to make a new chessboard out of the 4 we need 2 pieces with black cell on the (0,0) position and 2 pieces with white cell on the (0,0) position. Also note that once we know the color of (0,0) position we can make the whole chessboard out of it. So we find the cost of converting each piece into two chessboards — one with white cell at (0,0) and another with black cell at (0,0) and then we calculate the minimum of all possible ways. My solution
 » Just wanted to mention that F is essentially the same (actually more explicit) as an old POI problem: https://main.edu.pl/en/archive/oi/19/pre
 » How to solve problem D for N points and K lines?
 » Something about Problem G. I guess most of us get the formula below easily: But the Editorial above claims: So may anybody prove that: •  » » I would gladly hear the formal proof of equation myself since it doesn't sound like easy transformation.
•  » » 15 months ago, # ^ | ← Rev. 6 →   Here is a proof I thought of. Also, sorry for too many revisions :PConsider n students who wish to participate in a contest. They must enter themselves in exactly k non-empty groups. One of these groups is a special group who gets to participate in Div 1, while the others participate in Div 2. Furthermore, Alice, one of the students, is very good at coding, so she will always participate in Div 1. Furthermore, the special group has a team leader. We count the number of ways C of partitioning the students in two ways.First, we select, out of n - 1 students, j - 1 students who, along with Alice, form the special group. This can be done in ways. Now the n - j normal students can be partitioned in ways, and the team leader of the special group can be chosen in j ways. Thus .Another way is this: Suppose Alice is the team leader. Then simply partition the n students into k groups in ways, and the team Alice belongs to is special. Otherwise choose a team leader out of the remaining students in n - 1 ways (call this chosen leader Bob), and partition the n - 1 students other than Bob in ways. The one Alice belongs to is the special group, so Bob belongs to that group of course. Therefore .
•  » » » Yes, you are right, but you make exactly what problem G asks. Your proof is just a more formal than from editorial. In other words, formulas are same because they count same thing.What I (and probably, Blue233333) expected are just formal equivalent transformations of left and right parts using some properties of Binomial Coefficients and Stirling numbers.
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   With swm_sxt and Zsnuo's help, I find an approach to use equivalent transformations to prove that, but I am still a little confused. However, I don't understand the last step's formula transformations very clearly, while I could only understand it with this: Dividing n people into k non-empty groups, means that we first choose j, 0 ≤ j ≤ n - 1, people to be members of person n's group, and then divide the remained persons into k - 1 groups.
•  » » » » » You can check it at wikipedia.
 » There are n circles drawn on a piece of paper in such a way that any two circles intersect in two points, and no three circles pass through the same point. Turbo the snail slides along the circles in the following fashion. Initially he moves on one of the circles in clockwise direction. Turbo always keeps sliding along the current circle until he reaches an intersection with another circle. Then he continues his journey on this new circle and also changes the direction of moving, i.e. from clockwise to anticlockwise or vice versa. Suppose that Turbo’s path entirely covers all circles. Prove that n must be odd.
•  » » This is from IMO. Also, it is unrelated.
•  » » 1 + 1 = 2
 » can someone please explain me F. I didn't get the editorial :(
 » Vovuh can you explain "961E — Tufurama" more details so I can get it. Though I solved it using merge sort tree but I want to learn your solution approach.
 » I think problem D and 849B are a little alike. At least almost the same solution applies to both I guess.
 » Here is my blog post on the very elegant geometry problem D :)
 » i feel like my brain expanded after solving E xD