Edvard's blog

By Edvard, history, 6 years ago, translation,

Hello, Codeforces!

Educational Codeforces Round 7 will take place on 10 February 2016 at 18:00 MSK for the first and second divisions. You can read about educational rounds here and here.

<This paragraph was modified last time>

The round will be unrated for all users and it will be held with extented ACM ICPC rules. You will have two hours to solve six problems. After that you will have one day to hack any solution you want. You will have access to copy any solution and test it locally.

If you have ideas for some problems or maybe already prepared problems that you can't use in rounds or official competitions, you can write to me.

</This paragraph was modified last time>

Thanks a lot to Aleksa Plavsic allllekssssa who suggested the problems D, E and Ivan Popovich NVAL for the problem F. Also thanks to Mohammad Nematollahi Deemo who suggested the problem that was highly simplified and will be under the letter C.

The round was prepared by me, Edvard Davtyan. Thanks a lot to MikeMirzayanov we invented the problems A, B and C together. Also thanks to Maria Belova Delinur for checking the English statements, Aleksa Plavsic allllekssssa and Ivan Popovich for testing the problems.

We tried to make the problems easy but interesting. I think that the problems is mathematized a little. I hope you will enjoy the problems!

Good luck and have fun!

P.S.: The Codeforces Educational Rounds was recognized by Snarknews as the best project in competitive programming in 2015 (the picture below is the prize).

UPD1: The first phase of the contest is ended. You can hack any other solution.

UPD3: The round is over, the results is final.

• +313

 » 6 years ago, # | ← Rev. 3 →   +15 Thanks a lot for the rounds. I like that each problem is meant to illustrate a specific algorithm. I just have one question: Is it possible that you will make educational rounds rated soon? especially that the problems in the last couple rounds are new and not from some previous contests?
•  » » 6 years ago, # ^ |   0 Some of the problems were not new. Please don't downvote :(
•  » » » 6 years ago, # ^ |   +2 At first it wasn't new, but in the last couple rounds I see the announcement saying that the problems are new. (I think they are new because the announcement started to say the names of people who suggested the problems).
•  » » » » 6 years ago, # ^ |   +8 If it's first time you see a problem it doesn't mean it's new or not standardand those people who are mentioned in the announcement are just mentioned because they suggested standard problems not original problems
•  » » » » » 6 years ago, # ^ | ← Rev. 3 →   0 Sorry, but I suggested new and for me not so standard tasks :PNormally that doesn't mean someone didn't invent something similar before.
•  » » » » » » 6 years ago, # ^ | ← Rev. 2 →   -6 Ok maybe you did, but it's supposed that people suggest standard/old problems not new as it's mentioned in the announement If you have ideas for some problems or maybe already prepared problems that you can't use in rounds or official competitions, you can write to me.
•  » » » » » » » 6 years ago, # ^ | ← Rev. 2 →   +8 I really don't think the quote you mentioned means that the problems were not new. It says if you prepared problems "that you can't use in rounds".Sorry for the questions if you don't like it, it represents my opinion only. I just asked because in MikeMirzayanov's first announcement he said that the series will be unrated (for now).Unrated (perhaps for now);
•  » » » » » » » » 6 years ago, # ^ | ← Rev. 2 →   0 it's not that I don't like it I didn't mean to offense, I just wanted to say that the idea of educational round is to present problems that are standard (not like what you said the problems were new), so it can't be rated because of that.and about "that you can't used in rounds" I'm not sure what reasons that a problem can't be used in rounds other than because it's already used somewhere or it's too standard
•  » » » » » » » » » 6 years ago, # ^ |   +2 Well, I can not agree with you :PI had several rounds in the last half year and I can not organize every 15 days one contest. Also I invented a lot of tasks soon(at least 20), so for me it is much easier option giving it now to Edvard which prepares everything and on that way help to CF ;)I know you didn't talk about me, but I suppose here is many guys which will do the same thing!
 » 6 years ago, # | ← Rev. 2 →   +13 Thanks Edvard for mentioning me!I think the task for this round are more 'educational' than any other time :) Also I am sure that everyone will find something interesting and solvable.About my tasks, I think they aren't standard and I would happy to see such task on some contest where I am participant... Several times they were on line to be used for my regular competition :)Good luck and any feedback about tasks after round will be valuable :)
 » 6 years ago, # |   0 I love these Educational Series . They are truly great . Thanks to those are working behind on it. I would love to suggest not make this Series Rated . Because here we got a chance to make errors & to learn from those Errors & Hacked & again Think about the Problem twice .
 » 6 years ago, # |   -8 Excuse me sir Edvard, with all my respect, I do not understand your words "that you can't use in rounds or official competitions". Also, would such problem(s) be sent to you to use it/them in a contest or something?!
 » 6 years ago, # |   +1 The Codeforces Educational Rounds was recognized by Snarknews as the best project in competitive programming in 2015 (the picture below is the prize). Say whaaaat? O.oGratz!
 » 6 years ago, # |   +5 The Educational rounds have been excellent in featuring algorithms that are otherwise uncommon. Also, they let contestants experiment with the contest environment without fear of rating deduction, so trying new problem solving sequences and the such. I hope that these rounds will continue to be excellent :D
 » 6 years ago, # | ← Rev. 2 →   +8 Mathematical problems are the best. kudos to Edvard I think Educational round is at its best. Don't make it rated as it helps us to do/learn fearless coding at a competitive level. Thanks to MikeMirzayanov for polygon n all. Keep it up guys!
 » 6 years ago, # |   0 clash with IIIT hyderabad, Codecraft contest tomorrow.
•  » » 6 years ago, # ^ |   +8 Do both :)
 » 6 years ago, # | ← Rev. 2 →   +1 Thanks a lot for the round Edvard.I think that the round will be interesting and cool!
 » 6 years ago, # |   +51 Codeforces is an amazing community! Like none other. This place is supposed to be competitive, but instead, its such a supportive community. People are not just sharing their knowledge, they're doing so without any immediate tangible incentive in return! May God bless you MikeMirzayanov, may god bless all problem setters, editorialists, people who share their solutions in blogs, coordinators, and everybody involved in the process. Sometimes, people willingly encourage others who feel defeated and demotivated. I think the money the setters earn is nothing compared to what they give, and a lot many people share their approaches without any payment whatsoever. :) I feel humbled by you all, and I feel happy everytime I come here. I wish to become great programmers like you, and also great human beings like you. God bless codeforces!
•  » » 6 years ago, # ^ |   +37
 » 6 years ago, # |   0 You will have two hours to solve six problems. After that you will have one day to hack any solution you want. You will have access to copy any solution and test it locally.Does this also mean that you can hack a solution to a problem even though your submitted solution to that very problem didn't pass the pretests? Thanks!
•  » » 6 years ago, # ^ |   -6 Yes.
 » 6 years ago, # |   +5 F is really nice! Thanks!I understand the ideas, but I don't know how to implement them in a beautiful way.Looking forward to magical implementations.XD
•  » » 6 years ago, # ^ |   +50 Indeed. I didn't know it was possible to calculate this sum effectively... Until I solved this problem today.
•  » » 6 years ago, # ^ |   +28 f(n) = 1^k + 2^k + ... + n^k is a polynomial of degree (k + 1). So, using Lagrange's interpolation formula, it's possible to compute f(n) in O(klog(k)).
•  » » » 6 years ago, # ^ |   0 Why is the sum a polynomial of degree (k + 1)?
•  » » » » 6 years ago, # ^ |   +3 See the editorial. It's easy to prove by induction.
•  » » » » » 6 years ago, # ^ | ← Rev. 6 →   0 Thank you, now it's clear the induction step. I can make this more formally, for those interested. Denote . We want to prove that degree of Pk(n) is k + 1.Base case of induction after k: By the induction we know that deg(Pk - 1(n)) = k. Taking the derivative of P(1)k(n) = k·Pk - 1(n). This implies that deg(P(1)k(n)) = kTherefore deg(Pk(n)) is exactly k + 1.
 » 6 years ago, # |   +3 Oh, no... Math.. (((
•  » » 6 years ago, # ^ |   +55 Oh, yes! Math!
 » 6 years ago, # |   +8 E is really nice!
•  » » 6 years ago, # ^ | ← Rev. 2 →   +8 Thanks for nice words. I tried to contribute cool tasks. At least I hope problems D and E were interesting for solving :) Both tasks are easy for implementation and I will try to invent something similar in future !
 » 6 years ago, # |   +24 I want to sincerely thank the problemsetters. Especially the one who set D . I don't remember the last time I saw such a beautiful problem. How brilliant someone has to be to come up with such an elegant problem that can be written in problem statement in such a simple manner !! I am simply awed . Kudos!! :)
 » 6 years ago, # |   +13 Idea for D : You want to make d1 = n - 1, d2 = n - 2, ..., dn - 1 = 1 so that the sum is 0. The rest is just experimenting to find the solution.
•  » » 6 years ago, # ^ |   +5 I knew this idea and yet I couldn't solve :(
•  » » » 6 years ago, # ^ | ← Rev. 3 →   +8 One of the key ideas is that d_{n} multiplied by zero, so you can make of it anything you want.The pattern for solution is:Separate all in three groups: where d_i must be some even constant, where d_i must be some odd constant, and where i == n (you don't care about d_n at all).Solution the task for first group it is something like (a b c c b a), you can see that it has exact d_i's as you need (1, 3, 5...).To solve for second + third group put n in between of this sequence and append n after (e.g. a b c N c b a N), is has also exact d_i's as you need. (2, 4, 6...)(Example ans for n == 4) 1 3 3 1 2 4 2 4
 » 6 years ago, # |   +1 Educational Rounds are very helpful in learning new concepts and revising old concepts.Thanks for Educational Rounds. Keep it unrated.
 » 6 years ago, # |   0 How to hack other people? Can i lock the submission now, if I didn't do it earlier?
 » 6 years ago, # | ← Rev. 2 →   0 How to solve C?
•  » » 6 years ago, # ^ |   +1 one way is to split array in sqrt(n) blocks. for each block, you keep an set and do binary search on it
•  » » 6 years ago, # ^ |   +16 You can do some pre-processing. For each position, store the position of the next number that is not equal to it. Just traverse the array from right to left if array[i + 1] != ar[i] , then nextUnequal[i] = i + 1 else nextUnequal[i] = nextUnequal[i + 1] Now when you have a query(L,R,X) check A[L] if it's not equal to X, return L otherwise look at nextUnequal[L] if that's <= R, return that else return -1
•  » » » 6 years ago, # ^ |   0 Neat. Can't believe I did not see this. :) Used to solving these sort of problems.
•  » » » 6 years ago, # ^ |   0 It takes intelligence to see the simplicity in something complex. I was so sure this is segment tree problem, and later thought of sqrt-decomposition solution lol.
•  » » 6 years ago, # ^ | ← Rev. 3 →   0 For each index of the array keep the index of the next element which is not equal to current. Then the answer for query can be obtained like this: 1. if (a[l] != x) print l 2. else if (nxt[l] > r) print -1 3. else print nxt[l]
•  » » 6 years ago, # ^ |   0 For each position in array remember the last position of a number different that what you have at that position(denote it d[i]), then for each query check if tab[r] != x — r is the answer, if tab[r] == x and d[r] >= l — answer is d[r], else -1
•  » » 6 years ago, # ^ |   +4 What i did was to find maximum number in the interval. Then i also found minimum number in interval.If both are the same and they are equal to the number we dont want it to be equal to , we output -1.Else we look which of min and max are different from it and output one of them.But there are better solutions.
•  » » 6 years ago, # ^ |   +3 I did it a long way by having 2 segment tree, one which reports the minimum and other which reports maximum in the range [L, R]. If both of them are equal and equal to x then print -1 else find the position of one not equal to x. Since the numbers range is [1,10**6], store indexes of each number in a vector and then binary search on them to find position. Complexity: O((n+m)logn)
•  » » » 6 years ago, # ^ |   0
•  » » 6 years ago, # ^ |   0 can be solved using DP in O(N+M) time. The idea is to calculate the maximum length of subarray for each position such that the subarray contains the same number as the one in that position. You can do this in O(N) timeThen for each query go to array[l] . If this is not equal to x, tada! else jump to the position denoted by array[l] and the length of the precalculated subarray for position l. If this is within range, return the position, else -1
 » 6 years ago, # | ← Rev. 2 →   -65 sorry so much
 » 6 years ago, # |   +5 How to solve E?
•  » » 6 years ago, # ^ |   +23 Consider all children of 1, let them be v. We can calculate answers for each v separately, taking the maximum answer.Now, for each v, find all leaves that belong to v, and record their distance. Sort them in decreasing order, and the answer is max(d[i]+i) for 0-based distance array. The reason is that we can think in reverse way: the ants move from root to leaves, and we always want the furthest ant to move first.Btw, this question has appeared (exact problem) some year ago in a chinese contest.
•  » » » 6 years ago, # ^ |   +23 I am not doing chinese contests, but It looks as right decision to put this task on educationl round :)
 » 6 years ago, # |   +12 How to solve F?
•  » » 6 years ago, # ^ |   0
•  » » 6 years ago, # ^ |   +3 Simple interpolation: https://en.wikipedia.org/wiki/Lagrange_polynomial.
 » 6 years ago, # |   0 Hi- distance cantst got hold down.
•  » » 6 years ago, # ^ |   0 What ?
 » 6 years ago, # |   +3 How to determine the index of min element in algorithm segment tree? Is it right? My code for problem C
•  » » 6 years ago, # ^ |   +3 check 15945814 tree1 stores index of maximum element in a range and tree2 stores index of minimum.
•  » » » 6 years ago, # ^ |   +4 Thanks.
•  » » » 6 years ago, # ^ | ← Rev. 4 →   +4
•  » » 6 years ago, # ^ | ← Rev. 3 →   +4 I solved C with partial sums. Say we have to answer a query (X, Y, C): if sum of numbers in tha range [X, Y] is divisible by (Y-X+1) and sum in range [X, Y] divided by (Y-X+1) equals C then we have no element in range [X, Y] which is different from C. If we have a different element, we can binary search for the position of that different element.Here is my solutionLE: Nevermind, I missed a case
•  » » » 6 years ago, # ^ | ← Rev. 2 →   +12 Hacked :PLook at this sample :5 13 2 4 5 51 3 3your answer is -1, that isnt correct ;)
•  » » » » 6 years ago, # ^ |   +3 Yeah, while I was taking a shower I realised that my solution fails that test and that I shoould hack myself, but it seems like you already hacked my solution. :p
•  » » » » » 6 years ago, # ^ |   0 I solved it just like you did and I hacked myself too :p
 » 6 years ago, # |   0 Are there at all any test cases for which an answer might fail (after passing the pretests) for the problems A and B? It's been almost 5 hours now and I have tried everything but in the end it seems that the pretests cover up almost everything for both the problems!PS: Don't confuse this with me asking for helps to hack other's solutions. All I merely am asking is a yes or no to the question. Thanks! :)
•  » » 6 years ago, # ^ |   +3 There are many hacked solutions for A and B task, so possible some tricky testcases exist ;)
 » 6 years ago, # | ← Rev. 2 →   0 Deleted
 » 6 years ago, # |   0 Wow, I use to teach how to calculate interpolating polynomials, but in a straight-forward way...Couldn't believe they could be used in competitive programming until now!
 » 6 years ago, # |   +3 Problem C have really tight time limits. I wrote O(N) solution in Java and it exceeded the time limit on test 20. It only passed when I moved the solution to C++ with scanf/printf.I used BufferedReader and StringTokenizer in my java solution, so it's not a problem with slow Scanner class.
•  » » 6 years ago, # ^ | ← Rev. 3 →   +3 There was no time limits problem in your solution. Actually you have used System class to print the output which is quite slow. Also you have used println which is slower especially when it is used directly by System class(writing on console sending bytes, flushing the screen etc). To make it faster create an instance of PrintStream class and use that instance to write to the console. print("\n") uses '\n' as linefeed character and println() terminate the string with new line character depending on the platform. Best to use is '%n' with printf() in java.
 » 6 years ago, # |   0 I don't know Problem C very well.My program should output the position of any numbers not equal to xi in segment [li, ri]?If there are some positions what should I output?
 » 6 years ago, # |   0 Thanks for the round :)
 » 6 years ago, # |   +16 Can someones guess, what hack test could be in B? halyavin have already successfully done 116 hacks:D
•  » » 6 years ago, # ^ | ← Rev. 2 →   +19 May be .bat with tests.cpp.
 » 6 years ago, # | ← Rev. 2 →   0 I completely overkilled C and got TLE as a return gift.
•  » » 6 years ago, # ^ |   0 My approach-Build a segment tree in nlogn where each node has a vector of elements of its subtree in sorted order. 2 adjacent segments will have sorted elements and so merging can be done in O(n) leading to a total build complexity of nlogn. Queries will find the range in a segment which has 'x' and then return an index outside this range. Complexity of each search is therefore log^2(n).I realized after contest that all we need is minimum and maximum of a range to find any position which does not have x . Stupid me :/
 » 6 years ago, # | ← Rev. 2 →   0 Have the solution been rejudged already? With the full test cases and the successful hacks?EDIT: Spoke too soon
 » 6 years ago, # |   0 This is the first round that I can solve problem D, although I was not in the field.