### DmitryGrigorev's blog

By DmitryGrigorev, history, 2 weeks ago, translation, ,

Hi, Codeforces!

Im glad to invite everybody to the #546 Codeforces round, which will be held on Monday, March 11, 2019 at 19:35. The round will be rated for all participants from the second division (with rating below than 2100). As usually, we will be glad to see participants from the first division out of competition!

Problems for the round have been proposed by Fedor osaaateiasavtnl. Ushakov, Stepan IbragiMMamilov Stepkin, Alexey usertab34 Roze, Denis Denisson Shpakovskij and Alexander Ralsei Gladkov.

The round have been prepared by us, Dmitry DmitryGrigorev Grigoryev, Fedor osaaateiasavtnl. Ushakov, Semyon cookiedoth Savkin and Dmitry TheWayISteppedOutTheCar Piskalov.

We'd like to give thanks to Ildar 300iq Gainullin for excellent coordination of the round, Grigoriy V--gLaSsH0ldEr593--V Reznikov, Alexey Aleks5d Upirvitsky and Mohammed mohammedehab2002 Ehab for testing and to Mike MikeMirzayanov Mirzayanov as well for his unbelievable Codeforces and Polygon platforms.

You will receive 5 problems and 2 hours for solving it. During the round you will be helping for an extraordinary girl Nastya, who is studying in an usual school in Byteland.

Score distribution will be announced, traditionally, closer to the start of the contest.

UPD Score distribution is standart — 500-1000-1500-2000-2500

We're looking forward your participation.

UPD2 Thank you for your participation in the contest!

List of the winners of the contest:

Div.2

Div.1 + Div.2

My frank congratulations for all the winners!

The editorial will be posted very soon. We apologize for delay.

UPD3

The editorial

•
• +454
•

 » 2 weeks ago, # |   -115 We'd like to give thanks to Ildar 300iq Gainullin for excellent coordination of the round Is KAN finally gone? crab rave.mp4
 » 2 weeks ago, # |   +18 Let's hope difficulty gap will be normal
 » 2 weeks ago, # | ← Rev. 2 →   -9 We are waiting ¤_⊙
 » 2 weeks ago, # | ← Rev. 2 →   +75 I hope this contest makes my contribution positive.
 » 2 weeks ago, # |   +2 5 problems and 2 hours contest are really challenging. I am looking forward to participating in this contest and I wish to learn new things. :)
 » 2 weeks ago, # |   +3 Happiness is back!!
 » 2 weeks ago, # |   +65 Please, read all the tasks That's quite a new thing in an announcement.
•  » » 2 weeks ago, # ^ |   +35 Maybe he implies that the problems are not sorted by difficulty
•  » » » 2 weeks ago, # ^ |   0 if the problem is concise, that help
 » 2 weeks ago, # |   -38 Please, read all the tasksexcuse me? do you think being able to post a contest allows you to dictate what people should do? classic slav attitude...
 » 2 weeks ago, # |   -12 please don't keep a mathforces like last time
•  » » 2 weeks ago, # ^ |   -32 and also not a geometry one!
•  » » 2 weeks ago, # ^ |   -7 I like mathforces
 » 2 weeks ago, # |   -30 I wish i can reach 2100 this time
•  » » 2 weeks ago, # ^ |   -36 who cares about you to be honest
•  » » » 2 weeks ago, # ^ |   0 me
 » 2 weeks ago, # | ← Rev. 2 →   0 A contest with 5 problems:)
 » 2 weeks ago, # |   +16 Let's solve the problems just for rating!
 » 2 weeks ago, # | ← Rev. 2 →   0 Desire positive rating changes in this round!! :) UPDATE on Mar.12, 2019:I can not understand why some people voted my reply with negative attitude.I always believe that everyone desires positive rating changes. Maybe my opinion is a bit wrong.:(
 » 2 weeks ago, # |   +20 Five problems!
 » 2 weeks ago, # |   +25 Haven't seen a 5-problems contest in a while...
 » 2 weeks ago, # |   +2 A challenge contest! Looking for it! :) I believe that it can improve our skills!
 » 2 weeks ago, # |   0 Nastya from "Byteland" .....
 » 2 weeks ago, # |   +3 Score distribution ?
 » 2 weeks ago, # |   +9 hope short problems!
 » 2 weeks ago, # |   0 Good Luck :DNOT FOR contribution :3
 » 2 weeks ago, # |   +3 Auto comment: topic has been updated by DmitryGrigorev (previous revision, new revision, compare).
 » 2 weeks ago, # | ← Rev. 3 →   -18 Score distribution is standartstandard, dude
 » 2 weeks ago, # |   +38 Is MikeMirzayanov the owner of problem C ?
•  » » 2 weeks ago, # ^ |   0 Seems so, coz his problems are generally based on good idea/observation + quick/short implementation but if you haven't thought of the idea clearly then implementation can go pretty lengthy and fail on system tests
 » 2 weeks ago, # |   +24 Admin take some action against this user bb2211 he is hacking his solution from another id ragnar7.
•  » » 2 weeks ago, # ^ |   +10 I think you should block both users
 » 2 weeks ago, # |   +28 Insanely good difficulty balance.
 » 2 weeks ago, # |   +4 i'm the only one who take 30 min to understand D ?
 » 2 weeks ago, # |   +4 How to solve E?Also will the numbers fit in long long?
•  » » 2 weeks ago, # ^ |   +31 The number will obviously fit.E can be solved with segment tree + lazy propagation.2nd query will be discarded (just calling the get function).To do the 1st query, first update that single element without lazy propagation, then perform updating all elements id in the range [i + 1, mx] (inclusive) with , with mx as the maximum index that . mx could be found by binary search.
•  » » » 2 weeks ago, # ^ | ← Rev. 2 →   +8 How to handle update in range[i+1 ,mx] using lazy?
•  » » » » 2 weeks ago, # ^ | ← Rev. 6 →   +15 This part is pretty tricky. Here was my approach in contest:First of all, my segment tree is one maintaining range sum.You can see that the newly updated value is always strictly larger than the old one, thus if the lazy attribute for the working node already has some value, overwrite it.Each "lazy attribute" stores two values: the ai which causes the updating chain begins and its index i.When propagating from a node with lazy attribute, assume that the node cover the range [st, en]; you'll see that the sum should be overwritten into: .That one can be rewritten as .From here, the propagation can be done in O(1), with the help of prefix sum, or even nested prefix sum, in array k.
•  » » » » » 2 weeks ago, # ^ | ← Rev. 6 →   0 ok thanks i will look into it.
•  » » » » » » 2 weeks ago, # ^ |   0 Should be [i, st-2] and [st-1, en-1] for the limits, but yah, I forgot that. Edited. ;)
•  » » 2 weeks ago, # ^ |   +2 Tried to create a difference array from array A and array K, and tried updating the values of this diff array for query of type 1, it will turn most of the values of this diff array to 0.Query of type 1 will increase the diff value of only first element and make all other diff value 0. So, at most 2*n values need to be updated at most.Tried to maintain the index of non-zero values of this diff array using set,and then range update and range sum query using segment tree lazy propagation.
•  » » » 2 weeks ago, # ^ |   0 What does "Tried to" mean? Did it pass pretests?
•  » » » » 2 weeks ago, # ^ |   +5 yes it passed
•  » » 2 weeks ago, # ^ |   +15 The answer will fit inside of a long long. max(A) starts out  ≤ 109 and you can add at most 1011 to it, so A[i] will at most be around 1011, meaning the sum of the As will at most be around 1016. So everything should fit inside a long long without any problems.About the solution: You can reduce the problem to all k being 0 by working on instead of A. For B we have that B[i] ≤ B[i + 1] so it must always be increasing.To do the two types of queries I used binary search together with a lazy segment tree that allowed sum on intervals and set on intervals.To do the add query you need to add x to B[i] and then update the rest of B so that it is increasing, to do this you can apply binary search on B to find all indices j such that j > i and B[i] > B[j]. Then use the set on interval operation to make all of those B[j] equal to B[i]. This takes per query.To do the sum query just use the built in sum in the lazy segment tree. But this is a sum over B and not A, so you need to adjust the answer by removing the extra k you added in the beginning, which can be done by playing around with cumulative sums. This takes per query.
•  » » » 2 weeks ago, # ^ |   0 I did the same stuff but got TLE on test 19. I think there is a way to do add query in O(log n) by removing the binary search step and to find the position by only descending the tree on single-side.
•  » » » » 2 weeks ago, # ^ |   +5 Uhm so I'm currently using pypy and it passed all pretests, so I'm sure you can do it in C++ as well without any problems. You probably just need a quicker implementation of a lazy segment tree.But yeah, I think you can do a quicker binary search by having another lazy segment tree, this one allowing for set on an interval and maximum on an interval, and with that tree you could do the binary search in just .
•  » » » » » 2 weeks ago, # ^ |   0 Seeing my code now I realized I left a debug statement there involving flush after every query.
•  » » » » » 2 weeks ago, # ^ |   0 Can you explain in more detail how to do first query per O(logn)?
•  » » » » » » 2 weeks ago, # ^ |   +3 This is a pretty well known technique used on segment trees (and binary trees) in general, the idea is to start in the top and walk down the tree. If the maximum of the left child is  ≥ B[i] then walk to the left, else walk to the right. With this you can find the first index j such that B[j] ≥ B[i].This works straight up on segment trees, and can also be used on lazy segment trees, but then you will have to push lazily stored queries during the search.
•  » » 2 weeks ago, # ^ |   +30 There is a solution that do not uses segment tree tricks, just two plain seg trees, one with range += lazy and range sum other with range = and one get one element. You can notice that if you update a[i] += x that leads to a[i + 1] = a[i] + k[i] and so on from i to some l, than if you'll update a[i] += y again, you'll just make += on range(i, l). So this observations leads us to smth like DSU (disjoint set union). But there is one thing, when we get query update a[i] += x and i belongs to some [l, r] segment where l is strictly less than i this segment [l, r] splits to two [l, i — 1], [i, r]. So you need to do unusual DSU with segment tree (the one with range=). When you get a[i] += x query your steps is split range to which i belongs than go to right and merge some ranges (continue while conditions from statement is true), while merging make += on right range. It is clear that we will do at most n + q mergins, because we can merge only by two reasons 1 — it was originally disjont (thats n) or 2 — it was splitted (that's q). Complexity O((n + q) * log(n)) Submission for details 51198410
•  » » » 2 weeks ago, # ^ |   +17 Thanks! I followed your advice and got accepted. https://codeforces.com/contest/1136/submission/51236918 Instead of segment tree for the DSU-ish part, I used set of pairs. In your personal opinion do you consider this to be harder o easier to implement? I understood your explanation but I couldn't really understand your code.
•  » » » » 2 weeks ago, # ^ |   +20 I just didn't come up with set of pairs idea, I think it's better idea than using another segment tree. Strange I thought my explanation worse than code.
•  » » 2 weeks ago, # ^ |   +3 You can solve it using plain segment tree with lazy updates.Notice the fact that the values will be increasing. So, suppose that the i+1 th index is changed once due to the update on i'th index. Now, if somehow a[i] increases again, a[i+1] will increase by the same amount. Based on this, you can perform range updates. And number of these updates won't be that much.
 » 2 weeks ago, # |   +3 How to solve D guys?
•  » » 2 weeks ago, # ^ |   +1 If you can swap, do it immediately otherwise take the previous pupil to the farthest position from you, until nothing change
•  » » » 2 weeks ago, # ^ |   0 May be because I read D first but I find it clever with concise implementation though cannot get C correct
•  » » » 2 weeks ago, # ^ |   +20 This Greedy method will get TLE.
•  » » » » 2 weeks ago, # ^ |   +3 68th test case :(
•  » » » » 13 days ago, # ^ |   0 My solution can pass systest, you can see my submission here 51250678. But it got TLE at a simple test. So painful
•  » » 2 weeks ago, # ^ | ← Rev. 6 →   +22 We will iterate from the back of the queue (person before Nastya) to the front. We will store for each person i how many persons are after this person in the queue and are favored by person i, in fav[i]. Initially we set fav[i] for each person i that favors Nastya to 1. We will also maintain a variable that stores how many persons have been removed from the queue so far. Now if we are at person i and there are x persons removed, a total of rem = n - 1 - i - x persons remain to the right of this person. If fav[Q[i]] == rem, every person that remains to the right of this person is favored by this person, and thus this person can swap with each one of these. In this case we remove this person and increase our answer by 1. Otherwise we cannot remove it and we will increase fav for all the persons that favor this person.The complexity of this approach is O(N + M). https://codeforces.com/contest/1136/submission/51189237
•  » » » 2 weeks ago, # ^ |   +4 was thinking in the same lines.couldn't complete in time. BTW nice solution.
•  » » » 2 weeks ago, # ^ |   +1 I have done the same thing
•  » » » 2 weeks ago, # ^ | ← Rev. 2 →   0 Robbinb1993 what do you mean by favoured by person i? and after this person means to the right or to the left of person
•  » » » » 2 weeks ago, # ^ | ← Rev. 2 →   +2 If some person u is favoured by person i, it means person u is allowed to move places with person i, if person i is in front of person u in in the queue. So if all the remaining persons to the right of person i in the queue (towards the back) are favoured by this person i, he can move places with all of them and Nastya is able to move one place forward in the queue. In this case we 'remove' person i from the queue (that is we move it after Nastya).
•  » » » » » 2 weeks ago, # ^ | ← Rev. 2 →   +5 ok , thanks i understood it . great idea Robbinb1993
•  » » 2 weeks ago, # ^ | ← Rev. 2 →   +4 I just pushed every person that can let Nastya stay before him to the end of p[] (to the place before such persons that are already at the end), and then counted number of such persons in the end of p[].Observation: if person can not be pushed to the end, he can not ever let Nastya ahead.51192297
 » 2 weeks ago, # |   +31 Me in this round: Solve ABC in 12 minutes Stuck in like 90 minutes trying D Solve E at 118th minute. Lol.Good round, tight pretest (at least as of now I supposed) :DAnyway, any cool observations for D?
•  » » 2 weeks ago, # ^ |   +8 Moving from natasha to first guy, if you find the guy that can move to back of natash,then move it.
•  » » » 2 weeks ago, # ^ |   0 Dang, I was stupid! :(Thanks. ;)
•  » » » 2 weeks ago, # ^ |   +2 Can you please elaborate a bit?
•  » » » 2 weeks ago, # ^ |   +3 Is your solution working for this case as well?: 4 3 1 2 3 4 1 2 1 3 1 4 I think that the correct output should be 1, I think that your approach will return 0.
•  » » » » 2 weeks ago, # ^ |   0 It still works. You can see my solution here.The idea is, when traversing to position i, we'll consider the pupil initially standing at that position solely. And we'll move him/her through the very end, until blocked by someone not he/she isn't willing to swap places.There are only m relationships, and each only causes one swap, thus only maximum m swaps are performed.
•  » » » » » 2 weeks ago, # ^ |   +14 Had i been the online jidge ,i would have definetly passed all your solutions without checking for test cases...i mean just look at comment at the bottom
•  » » » » » » 2 weeks ago, # ^ |   0 LOL. If only that applies in real judges :D
•  » » » » » 2 weeks ago, # ^ |   0 I really loved Ur solution .. I was thinking it completely the wrong way
 » 2 weeks ago, # |   +21 DmitryGrigorev Read all tasks :PNice contest, though missed E (knew idea)
 » 2 weeks ago, # |   +18 Good tasks, thanks!
 » 2 weeks ago, # |   0 Someone please explain C.
•  » » 2 weeks ago, # ^ |   0 Each respective diagonal in the matrix must have the same elements.
•  » » » 2 weeks ago, # ^ |   0 Can u please elaborate. It would be great help.
•  » » » » 2 weeks ago, # ^ | ← Rev. 2 →   0 for matrix,[1 2 3][4 5 6][7 8 9]all the diagonals are [1], [4, 2], [7, 5, 3], [8, 6], [9]required matrix,[1, 4, 7][2, 5, 6][3, 8, 9]all the diagonals are [1], [2, 4], [3, 5, 7], [8, 6], [9]so here we can see those respective diagonals have the same elements so the answer will be "YES" otherwise "NO".
•  » » » » » 2 weeks ago, # ^ |   0 Can u tell why?
•  » » » » » » 2 weeks ago, # ^ | ← Rev. 4 →   +15 Each time you transpose any square submatrix, every element stays on the same respective diagonal. And by transposing 2x2 matrix, you can perform swap for adjacent elements in the diagonal, therefore, you can sort these elements in the diagonal.
•  » » » » » » » 2 weeks ago, # ^ |   0 Got it! Thanks.
•  » » » » » 2 weeks ago, # ^ |   0 starboy_jb how you saw this observation?
•  » » 2 weeks ago, # ^ |   0 Notice that you can imitate transposition of every matrix by little transpositions of matrices 2x2. That's because transposition of matrix 2x2 swaps two nearby elements on the diagonal, and transposition of matrix nxn swaps some elements on every it's diagonal (elements that are on a diagonal remain on that diagonal). But you can imitate every permutation by some swapping nearby elements.
•  » » » 2 weeks ago, # ^ |   0 What abt sorting?
•  » » » » 2 weeks ago, # ^ |   0 Got it!. Thanks
•  » » 2 weeks ago, # ^ |   +1 I noticed that transpose does not change the sum of row+column. That's why I just verify that both matrices have values with equivalent sums. I did not prove it though.
 » 2 weeks ago, # |   0 How to solve C?
•  » » 2 weeks ago, # ^ |   0 Each respective diagonal in the matrix must have the same elements.
 » 2 weeks ago, # |   0 Anyone knows why I can't use auto in my compiler (codeblocks)
•  » » 2 weeks ago, # ^ |   +6 Check in your "Compiler settings" if you'd enabled C++11 features yet.
•  » » 2 weeks ago, # ^ |   0 Enable ISOC++11 or ISOC++14 standards under compiler settings
•  » » 2 weeks ago, # ^ |   0 setting -> compiler -> c++14 ->OK
 » 2 weeks ago, # |   0 Soooooo shitty pretests in C
•  » » 2 weeks ago, # ^ |   +8 Yeah. My stupid bugs failed only on 21th pretest. It's was awful
•  » » 2 weeks ago, # ^ |   +9 Any idea what the hacks were for problem C ??
•  » » » 2 weeks ago, # ^ | ← Rev. 2 →   +11 Maybe something like this Spoiler3 31 1 11 1 12 1 11 1 11 2 12 1 1
•  » » » 2 weeks ago, # ^ |   +2 Apparently all matrices in pretests were square but matrices can be nonsquare.
•  » » » » 2 weeks ago, # ^ |   +2 Damn, those are shit weak pretests
•  » » » » 2 weeks ago, # ^ |   +50 That's definitly false
•  » » » » » 2 weeks ago, # ^ |   +3 A few people passed pretests for C even though they used n where they should have used m, so we thought there were only square matrices in the pretests. Thanks for the correction.
•  » » » 2 weeks ago, # ^ |   0 Something Like: 2 2 1 2 2 1 1 1 2 1Basically some solutions didn't test for equivalent diagonals but just checked that each element in some diagonal of A has at least one equal element in same diagonal of B
•  » » » 2 weeks ago, # ^ |   0 One error I saw some people made is that they checked that the list formed by adding together a diagonal from A with the equivalent diagonal from B had an even number of each integer. This breaks, for example, when a diagonal in A contains two 1's and the corresponding diagonal in B contains two 2's.
 » 2 weeks ago, # | ← Rev. 2 →   +39 Why do people use fake accounts to increase rating? This user bb2211 has hacked 7 solution of his fake account ragnar7 in this contest, thereby getting +700 points. Hacked soultions — https://codeforces.com/contest/1136/submission/51194910 https://codeforces.com/contest/1136/submission/51194506 https://codeforces.com/contest/1136/submission/51194345 https://codeforces.com/contest/1136/submission/51194130 https://codeforces.com/contest/1136/submission/51193823
•  » » 2 weeks ago, # ^ |   +15 He definitely will be disqualified.
•  » » 2 weeks ago, # ^ |   +7 How did he manage to get 7 fake accounts in same room?
•  » » » 2 weeks ago, # ^ |   +7 One fake account, and hacked 7 solutions of the same. Check the hacked solutions link. They are like if(n==199) cout<<"Wrong Answer".
•  » » 2 weeks ago, # ^ |   +1 They think good rating makes them look cool xD so silly I care about my rating just because that means I have improved
•  » » 2 weeks ago, # ^ | ← Rev. 4 →   +13 apparantly I_love_sad_crying_cats noticed this during the contest and got benefited with bb2211's kid play ;) Lol..well played I_love_sad_crying_cats !
•  » » » 2 weeks ago, # ^ |   +3 Haha:D, Karma plays well.
 » 2 weeks ago, # | ← Rev. 2 →   0 Weak pretests for A
•  » » 2 weeks ago, # ^ |   +31 *pretests
 » 2 weeks ago, # |   +6 Isn't it easy?
 » 2 weeks ago, # |   0 You may want to check this out: https://codeforces.com/blog/entry/65873
 » 2 weeks ago, # |   +13 good contest with interesting problems
 » 2 weeks ago, # |   +9 who else got WA on problem C? I think most of us(
•  » » 2 weeks ago, # ^ |   +1 I got. Very stupid mistake. the amount of diagonals is n + m -1, isn't 2 * n-1. With this mistake my solution broken down only on 72 test.
 » 2 weeks ago, # |   +11 Problem 'C' was really nice. Thanks to writers :)
•  » » 2 weeks ago, # ^ |   0 ghanta , d was good
 » 2 weeks ago, # | ← Rev. 3 →   0 Seems like D doesn't have worst case tests, my solution having worst case n^2 passed in 795 ms. I am iterating through all degrees of last person in decreasing order and adding this to answer if you can reach nearest to last person by continous swaps with adjacent person. https://codeforces.com/contest/1136/submission/51194411 Clearly n^2 when last person is linked to first half of people, and all of those half are connected (moving back) for every other node. Am i missing something here?EDIT: Got it! There are only m relationships between people so only that much swaps can be there. So it is (NLogN+(M+N)) and not (N*N). really nice question!
 » 2 weeks ago, # |   +1 My code for D got TLE on system test: https://codeforces.com/contest/1136/submission/51194792But resubmitting the same code without any changes passed: https://codeforces.com/contest/1136/submission/51197516 and https://codeforces.com/contest/1136/submission/51197653
•  » » 2 weeks ago, # ^ | ← Rev. 3 →   +4 it just passes on re-submission. once with 19ms gap and once only 4. Server tends to have some measurement error for different run of tests depending on processing load and bunch of other stuff. Check https://codeforces.com/blog/entry/49965#comments for more info.
•  » » » 2 weeks ago, # ^ |   0 Yeah, Realized that. Thanks for the comment link.Mistake on my part for not including fast I/O. Using fast I/O reduces the runtime to 732 ms from 1980 ms: https://codeforces.com/contest/1136/submission/51196918Guess cin/cout are really slow in C++
 » 2 weeks ago, # | ← Rev. 2 →   +29 Hey MikeMirzayanov, this user cs_tree skips his solution, whenever there is a chance of huge decrement in his rating. This is the second time I've seen him do this.Screenshot during the contest : Screenshot after the system testing was completed : He submits the solution in C++ whenever he wants to get his solution skipped. Here is a screenshot of his previous skipped contest. This kind of behavior is unacceptable. Please look into this matter and take strict actions against this kind of people. It is very disheartening for people who give contests regularly and go through the ups and downs in their rating.
•  » » 2 weeks ago, # ^ | ← Rev. 2 →   -10 how it is done , how to skip a solution . As far as i know , if u want to skip a solution , submit same solution from different account , codeforces will give u system warning and ur solution will be skipped , but if this continues to 2 or more times ur accnt will be blocked ? am i right MikeMirzayanov
•  » » » 2 weeks ago, # ^ |   +4 To find those ninja techniques participation in contests is a must.
•  » » » » 2 weeks ago, # ^ |   -27 abe bsdk , tere ko kahe lagta hai ki ham contest me participate nahi karte .
•  » » » » » 2 weeks ago, # ^ | ← Rev. 2 →   0 Your colour shows that you don't participate.I don't know it Colorless is new lgm.
•  » » » » » » 2 weeks ago, # ^ |   -29 gadha hai to gadha hi rahega na . akal to kabhi aayegi nahi chutiye
•  » » 2 weeks ago, # ^ | ← Rev. 2 →   0 ot .
 » 2 weeks ago, # | ← Rev. 2 →   -6 Hello, I received a message saying that my solution for Div2D coincides with the code of other users. The code is clearly different and for a problem with such a short solution it is likely for the code to be similar. Please look into this.Here is the submission which got flagged: https://codeforces.com/contest/1136/submission/51189268
 » 2 weeks ago, # |   +11 Very weak pretests for D. In hurry I didn't notice, that edges are directed and passed all of pretests. Rip rating. 51184494
 » 2 weeks ago, # |   0 How to solve D ? Any one ? !
•  » » 2 weeks ago, # ^ |   +4 We claim that the optimal construction is as follows.Maintain a "bubble list", which initially contains only Nastya. Then, iterate through every person in line, starting with the one directly in front of Nastya. If this person can be passed by every person in the bubble list, then move them back until they're behind Nastya and increment the answer by one. If there is a person in the bubble list who cannot pass the current pupil, add the current pupil to the bubble list.Clearly, this construction is valid given the problem parameters. To prove that it is optimal, suppose that there is some pupil A who cannot be passed by some person B, who himself cannot get behind Nastya in the line. No move except for B directly passing A will put B in front of A, so A cannot get behind B, meaning A cannot get behind Nastya. So, any person who cannot be passed by someone in the bubble list cannot get behind Nastya no matter what sequence of moves we use. (To formalize this argument, we'd need to use induction, since we implicitly assume that the bubble list is "correct" before processing each pupil.)In terms of efficiency, iterating through every pupil is O(N). Checking to see if a pupil can be passed by everyone in the bubble list is O(N) in the worst case, but because there are only M passing pairs, this operation takes only O(N+M) operations. The most intuitive way to check whether one pupil can be passed by another is to use a set or a sorted list, either of which support queries in O(log N). So, the efficiency of our algorithm is O((N+M) log N), which easily passes.
•  » » » 2 weeks ago, # ^ | ← Rev. 2 →   +1 this person can be passed by every person in the bubble list, then move them back until they're behind Nastya move them back or move him back .. i couldnt understand athis lineand add the current pupil to the bubble list.. should we add before natsya or after natsya
•  » » » » 2 weeks ago, # ^ |   +1 When we reach a certain person, the only people between that person and Nastya will be the people from the bubble list. So, we can just have that pupil be passed by everyone from the bubble list, at which point he will be behind Nastya. The order of the bubble list does not matter, as this won't affect whether any future pupil can be passed by every person on the bubble list.
•  » » » » » 2 weeks ago, # ^ |   0 Hey! Thanks for the great solutionI'm getting TLE, because for each person in the queue, I'm checking all the bubble list, resulting in a n^2 running time."...but because there are only M passing pairs, this operation takes only O(N+M) operations". Could you please explain how can I do this? I'm not seeing itThank you!
•  » » » » » » 2 weeks ago, # ^ | ← Rev. 2 →   0 To implement this operation with only O(N+M) total queries, we need to stop checking immediately after finding a person from the bubble list who can't pass the pupil we're checking. Here's what it would vaguely look like to check a pupil A: works = true for B in bubbleList: if (!canPass(B, A)): works = false break This way, we continue the loop only if all the elements we've checked so far can pass A, which means that we'll continue the loop at most M times.
•  » » » » » » » 2 weeks ago, # ^ |   0 Perfect! Thank you again
 » 2 weeks ago, # |   +9 https://codeforces.com/contest/1136/submission/51188835 why is my solution skipped? MikeMirzayanov 300iq
 » 2 weeks ago, # |   +3 ETA of editorials??
 » 2 weeks ago, # |   0 D had weak systests. My n^2 solution passed. For example try it with this test: #include using namespace std; int main() { cout << 300000 << ' ' << 300000 / 2 - 1 << '\n'; for (int i = 0; i < 300000; ++i) cout << i + 1 << ' '; cout << '\n'; for (int i = 1; i < 300000 / 2; ++i) cout << i << ' ' << 300000 << '\n'; } On the other hand, C had weak pretests, so it didn't catch solutions which assumed square matrices so I guess that evens it out?
•  » » » 2 weeks ago, # ^ |   0 Compiler magic happened because you hard-coded the input and indeed I can reproduce that on my machine. But there is no way that can happen if it is read from file and it doesn't happen on my machine neither with gcc nor clang.
•  » » » 2 weeks ago, # ^ | ← Rev. 3 →   0 If the compiler treats: for (int y : bad) if (g[y].find(x) == g[y].end()) good = false; as for (int y : bad) if (g[y].find(x) == g[y].end()) { good = false; break; } which is functionally equivalent to the previous code but more efficient then the complexity drops to (N+M)log N. I don't know if it does, though.
 » 2 weeks ago, # |   +3 next contest is after 4 weeks?
•  » » 2 weeks ago, # ^ |   +1 There will surely be many contests in between. Wait for a couple of days, they might not be declared yet.
•  » » 12 days ago, # ^ |   0 noobcoder92 have a look now on the contest page. One is declared. Still there can be more contests :)
 » 2 weeks ago, # |   +9 My solution to problem c passed pretests including test case 10 but it failed system test with TLE on test 10. Same solution got successfully submitted in practice. 51188133
•  » » 2 weeks ago, # ^ |   +3 The same happened to me
•  » » 13 days ago, # ^ | ← Rev. 3 →   -8 I met the same problem.During the contest, this code got TLE on test 10. Then I changed the range of my arrays from 500 to 5000, and the new submission got AC.After the contest, I re-submitted the same solution with arrays of range 500 and got AC.I think the test data before were incorrect, and maybe after the contest, the author corrected them. Why doesn't Codeforces rejudge all submissions of this problem? It's not fair. MikeMirzayanov
•  » » » 13 days ago, # ^ |   0 Why can't people learn to add three magic lines to speedup their cin?
•  » » » » 13 days ago, # ^ |   0 Oh! Thanks for your reminder!
 » 2 weeks ago, # |   +6 Always waiting for editorial.
 » 2 weeks ago, # |   0 I think ratings are not properly updated. I have solved only one question and my rating has dropped. I am a newbie with a previous rating of 816 and my current rating is 769.
 » 2 weeks ago, # |   +4 For prob A, I forgot a "=" but still pass the pretests, but after the contest I failed at test 54 :((
 » 2 weeks ago, # |   +44 We're looking forward your Editorial.~~~
 » 2 weeks ago, # |   0 E can be solved using Segment Tree Beats, eliminating the need for a tricky binary search.Code: 51225191
•  » » 2 weeks ago, # ^ |   0 how ? can u explain .
 » 2 weeks ago, # |   0 How to solve Div2 problem C?
•  » » 2 weeks ago, # ^ |   +5 you can prove that every number can't get away from right-diagonals(from right to left diagonals), but at every diagonal you can make every permutation by transpont 2*2 squares(with 2*2 square you can swap every neighboring elements, and get any permutation)
•  » » » 2 weeks ago, # ^ |   0 Can you elaborate a little further? thanks
•  » » » » 2 weeks ago, # ^ |   0 number stay at diagonal, if y + x = const, so when we change matrix — coordinats of every element changes like: y + x => y — i, x + i. => element stay at diagonal, because y + x = y — i + x + i
•  » » 2 weeks ago, # ^ |   0 and all you need is check, that muultisets of elementsa at every right-diagonal in both matrixes are equal
 » 2 weeks ago, # | ← Rev. 3 →   0 delete
 » 2 weeks ago, # |   +5 Hello, how long does it usually take for the editorial to be released? I'm soooo looking forward on checking how to solve questions D and E.
 » 2 weeks ago, # |   0 Auto comment: topic has been updated by DmitryGrigorev (previous revision, new revision, compare).
•  » » 2 weeks ago, # ^ |   0 with code with problem e , i cant figure out how to solve it .
 » 13 days ago, # |   -6 Thanks for a fast editorial!
 » 13 days ago, # | ← Rev. 2 →   0 Test data of D is weak.My submission passed test but it's hackable by data I wrote below. 5 5 1 2 3 4 5 1 3 1 4 1 5 3 5 4 5 `The answer is 2, but my submission prints 3.
 » 13 days ago, # |   0 Can anyone explain why in C using an unordered multiset is giving a TLE but using a vector and sorting and comparing passes? I think the time constrains are too rigid in this questionUNORDERED MULTISET https://codeforces.com/contest/1136/submission/51269981
•  » » 12 days ago, # ^ |   0 Try adding ios_base::sync_with_stdio(0) to your code. The longest part is input and this line speeds it up.