### Um_nik's blog

By Um_nik, history, 6 months ago, ,

Hello!

I'm glad to invite you all to Round 576 which will take place on 30.07.2019 17:35 (Московское время).

There will be 6 problem in both divisions.

Round is based on Team Olympiad in Computer Science Summer School. It is (yet another) summer school for schoolchildren organized by Higher School of Economics and "Strategy" Center in Lipetsk. Almost all the problems are authored and prepared by teachers and teaching assistants in CSSS: Um_nik, Burunduk1, I_love_fake123, MakArtKar, Villen3tenmerth, Aphanasiy, Gadget. One of the problems is authored by Merkurev (just because we are friends :) ). One more problem for the round was added by KAN.

I would like to thank KAN for CF round coordination, I_love_Tanya_Romanova, Merkurev, Rox and tractor74.ru for testing, and Codeforces and Polygon team for these beautiful platforms.

Scoring will be announced.

Upd: We added one more problem to div.1 contest, now both contests have 6 problems (4 in common). The round is not combined, if it were, I would write "combined" in the title.

Scoring distribution:
div2: 500-750-1250-1750-2500-3000
div1: 500-750-1250-1500-1750-2250

Congratulations to our winners!
div.1:
2. tourist
3. mnbvmar
4. Benq
5. pashka
div.2:
1. ChthollyNotaSeniorious
2. Honour_34
3. ldxcaicai
4. shogunator
5. Yatsumura

Editorial won't be published.

• +192

 » 6 months ago, # |   +4 Auto comment: topic has been updated by Um_nik (previous revision, new revision, compare).
 » 6 months ago, # |   +99 Wow wide range of writers ( LGM to pupil )
 » 6 months ago, # |   -25 Looking for a crazy contest :P
 » 6 months ago, # | ← Rev. 3 →   -22
•  » » 6 months ago, # ^ | ← Rev. 2 →   +57 Guess, Mike is a part of "Codeforces and Polygon team".
•  » » » 6 months ago, # ^ |   +84 Sorry, I shouldn't have made such non-sense comment. I won't repeat this again. :)
•  » » » » 6 months ago, # ^ |   -12 HHAHAHAA
•  » » » 6 months ago, # ^ |   +13 Well, he is not saying that they didn't thank Mike, he is saying that they didn't specially thank Mike.
 » 6 months ago, # | ← Rev. 2 →   +147 Will there be stories about Um_nik's teal hair?
•  » » 6 months ago, # ^ |   0 I also want to know something about his hair,ha-ha.
 » 6 months ago, # |   -35 Why You forgot to thank specially to MikeMirzayanov for Codeforces and polygon platform? He can block your account chinese!
 » 6 months ago, # |   +15 Oh~,long time without a div1+2 conbined contest.I was excited as soon as I saw this contest appear in the list of upcoming contests.Hope the problem ststements will be as short as the announcement!\XD
•  » » 6 months ago, # ^ | ← Rev. 2 →   +28 The last Div.1 + Div.2 contest was Codeforces Global Round 4 (and the last Codeforces Round was Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2), 10 months ago), but is today's contests Div.1 + Div.2? I think only the notice says that way, and these are two separate contests.
•  » » » 6 months ago, # ^ |   +11 No, there have been many Div 1 + 2 combined rounds, just not labelled as such. The Mail.Ru rounds and Global rounds were all Div 1 + 2.
•  » » » » 6 months ago, # ^ |   0 Oh- I missed that. I thought only Codeforces Round #NNN, but you are right. I should edit the part of that. (And anyway, what do you think about my question?)
•  » » » » » 6 months ago, # ^ |   0 Yeah, today's round is not Div. 1+2 as per the convention I have seen and they should omit it from the blog post title.
•  » » » 6 months ago, # ^ |   0 There will be 6 problem in division 2 and 5 problems in division 1.
•  » » » » 6 months ago, # ^ |   0 I was saying this out of strange after seeing it.
 » 6 months ago, # |   -40 I wanna get high rating.
 » 6 months ago, # |   -33 looking forward to getting a high rank，last few contests I didn't perform well
 » 6 months ago, # |   0 points or plus ???
•  » » 6 months ago, # ^ | ← Rev. 2 →   0 Points because this is Div.1 and Div.2 Round, neither Div.3 Round nor Educational CF Round..
•  » » » 6 months ago, # ^ |   +6 thank you
•  » » » » 6 months ago, # ^ |   +6 Oh! Kizaru San, when are you going to Wano ?
•  » » » » » 6 months ago, # ^ |   +4 hmmm, i will, if Akainu agree
 » 6 months ago, # |   0 Anybody knows the difference among div.1+div2 and 2 separate rounds?
•  » » 6 months ago, # ^ |   +3 Div.1 + Div.2 Round is One contest in which Div.1 participants and Div,2 participants participate altogether and 2 seperate rounds are literally Two contests in which participants participate in his own Division.
 » 6 months ago, # | ← Rev. 2 →   -6 Why results of div1 and div2 is n
 » 6 months ago, # |   +104 I think Um_nik has not much experience to make a good contest, so I will not write this contest.
•  » » 6 months ago, # ^ |   +210 Oh no, please write our contest!!!!!1!
•  » » » 6 months ago, # ^ |   +29 what happened to your hair ?
•  » » » » 6 months ago, # ^ |   +92 I died dyed them
•  » » » » » 6 months ago, # ^ |   0 Good to know :)
•  » » » » » 6 months ago, # ^ |   +21 MWM, for a moment I thought that after solving many problems your hair started changing its colour!Btw, I think is better if you dye it one part red and the other black (just like nutella)
•  » » » » » 6 months ago, # ^ |   0 You look like a combination of Limmp and Ramzes666.
•  » » » » 6 months ago, # ^ |   +67 He want to say he's the king of cyans, since he worth more than 1000 cyans
•  » » » » » 6 months ago, # ^ |   +89 Um_nik is the new exchange coin, he worths 1024 cyans, 256 blues, 64 purples, 16 yellows, 4 reds, one nutella.
 » 6 months ago, # |   +70 Usually when one puts + between "Div. 1" and "Div. 2" it means a combined round, and names for posts for regular separate rounds don't contain a substring Div at all. You explained the separateness of the round in the update and wrote explicitly that each division has 6 problems (4 in common), but anyway I suggest not to use the + sign to denote separateness next time(s), otherwise someone will be confused.
•  » » 6 months ago, # ^ |   +43 Yes, I understand the confusion. I didn't know that there is a fixed convention, sorry.
 » 6 months ago, # |   -21 How long the contests are?
•  » » 6 months ago, # ^ |   +12 2 hours. It's on the contest page.
 » 6 months ago, # |   +46 "We added one more problem to div.1 contest" <3
•  » » 6 months ago, # ^ |   0 It will be easier than all others. At least in my opinion.
•  » » » 6 months ago, # ^ |   0 Which problem was added?
•  » » » » 6 months ago, # ^ |   -22 A
•  » » » » » 6 months ago, # ^ |   +23
 » 6 months ago, # |   +5 why start at 17:35, why not at 17:30?
•  » » 6 months ago, # ^ |   0 It may be farfetched, but (because) it's usual start time of the contest. So, is there a reason why the competition must start at 17:30?
•  » » 6 months ago, # ^ |   +50 It's good to think that the contest starts at 17:30, because of the registration.
 » 6 months ago, # |   -46 Is it rated?
•  » » 6 months ago, # ^ |   +6 Obviously ! <3
•  » » » 6 months ago, # ^ |   +11 My teacher told me not to assume anything beforehand
•  » » 6 months ago, # ^ |   +85 Probably not. You know, rounds by Um_nik are never rated.
 » 6 months ago, # |   +3 hello :D I have a doubt. What is a hack?
•  » » 6 months ago, # ^ |   +16 When you are able to prove some submission wrong by providing a clever test case whose output is wrong according to tester code/verification of output by the system. Hope it helps:D
•  » » » 6 months ago, # ^ |   0 thank you
•  » » 6 months ago, # ^ |   0 At codeforces , you can see the code written by others. So after you see others code which have passed the pretest, if you think there may be some data that his or her code may give the wrong answer, you can submit a piece of data ,and if his or code give the wrong answer , that means you hacks successfully, and you will get point, otherwise, you will loss point.
•  » » » 6 months ago, # ^ |   0 thanks
 » 6 months ago, # |   +3 gl & hf all
 » 6 months ago, # |   0 the number of registration in div.2 must be over than 10k before contest!
 » 6 months ago, # |   0 Scoring please
 » 6 months ago, # |   +3 Scoring doesn't seem to add up for common problems. Interesting...
 » 6 months ago, # |   +3 It would be a good contest excited to solve problems.
 » 6 months ago, # |   +70 I can see there's nothing strange about the performance of HanwhaEagles in this contest.
 » 6 months ago, # | ← Rev. 2 →   +3 After a long time you see so many full scores in Div 1 and hacks too, indicating "Author's mind is weak" Um_nik
•  » » 6 months ago, # ^ |   -43 What is your problem with full scores?
•  » » » 6 months ago, # ^ |   -7 However hard I try, I can't get it right. My mind is weak. But seeing so many full scores makes me feel Author doesn't have hard/interesting questions.
•  » » » » 6 months ago, # ^ |   +20 Your handle doesn't check out.
•  » » » 6 months ago, # ^ |   +18 In general, it's not good to break ties between too many contestants at the top just based on time. Doesn't matter much in a CF round compared to World Finals of Serious Competition, though.
 » 6 months ago, # |   +15 Where is tag "square round"? (576 = 24*24)
 » 6 months ago, # |   0 How to solve D
•  » » 6 months ago, # ^ |   +1 For queries of type 2 maintain range max query and assign proper value after all queries. Code: https://codeforces.com/contest/1199/submission/58010154
•  » » 6 months ago, # ^ |   +1 I used Lazy propagation on a range max segment tree (though the range max is not required).Please find my submission here.
 » 6 months ago, # |   +4 This contest made me sad
 » 6 months ago, # |   0 How to solve Div2D?
•  » » 6 months ago, # ^ | ← Rev. 2 →   +12 Process queries in offline mode. Hint: we don't care what queries of type "2 x" there were before the last query "1 p x" for every p. We just need to take the maximum of the x in the last "1 p x" query for a certain p and all x's from queries of type "2 x" that occurred later. Suffix maximums may be calculated easily in O(n).
•  » » » 6 months ago, # ^ |   +2 So Range Max segment tree was an overkill. :|
 » 6 months ago, # |   0 How to solve D?
•  » » 6 months ago, # ^ |   +1 Segment tree.
•  » » » 6 months ago, # ^ |   0 It can be solved without using Segment Tree
•  » » » » 6 months ago, # ^ |   +1 OK,I know.But Segment tree is easier to think:DI used 10 minutes to solve this problem with it.
•  » » » » » 6 months ago, # ^ |   0 I also tried to solve using segment tree but had some bug in my code :(
 » 6 months ago, # |   0 How to solve B :D
•  » » 6 months ago, # ^ | ← Rev. 2 →   0 l^2 — h^2 = 2hx. Find x. Because length of segment A-top of flower remains same.
•  » » » 6 months ago, # ^ |   0 how you came up with this equation?
•  » » » » 6 months ago, # ^ | ← Rev. 4 →   +1 Pythagorean theorem
•  » » » » 6 months ago, # ^ |   0 from the given image, we can see A^2 + L^2 = (H+A)^2then by simplifying the above equation A^2 + L^2 = H^2 + 2HA + A^2. then by eliminating A^2 from both sides L^2-H^2 = 2HA then A = (L^2-H^2) / 2H
•  » » » » » 6 months ago, # ^ |   0 Makes sense. Thanks.
•  » » » 6 months ago, # ^ |   0 Please how did you come up with this. I had to use cosine rule which took me time.
•  » » 6 months ago, # ^ |   0 I think this is an isosceles triangle :3
•  » » » 6 months ago, # ^ |   0 Which triangle is an isosceles?
•  » » » » 6 months ago, # ^ |   0 If you connect the line from two flowers like a drawing for you to create a triangle. Calling the three vertices of that triangle respectively A, B, C with B and C are respectively flowers. I noticed that triangle ABC is an isosceles triangle
•  » » » » » 6 months ago, # ^ |   0 And ABC is an isosceles triangle with AB = AC. You can easily find :3
•  » » » » » 6 months ago, # ^ |   0 And how did you notice that?
•  » » » » » » 6 months ago, # ^ |   0 Because length of segment A-top of flower remains same.
•  » » 6 months ago, # ^ |   0 A^2 + L^2 = (H+A)^2Use binary search to find A. For me binsearch is simpler than separating A in that formular.
•  » » » 6 months ago, # ^ |   +9 Is it really that difficult in the end it is just ( L^2 — H ^ 2 ) / 2 * H
 » 6 months ago, # |   -19 i think E can be solve by blossom algorithm,
•  » » 6 months ago, # ^ |   -19 but i dont know how to implement in O(V sqrt E). Can you give me some link, please?
•  » » » 6 months ago, # ^ | ← Rev. 3 →   +67 There is no way to find the maximum matching in general graph in $O(V\sqrt{E})$. As far as I know, the complexity of the fastest algorithm for this task is $O(VE)$.This is my solution for E (I cannot implement it in time :( ): Find a maximal matching $M$ in the given graph (a matching such that no more edge can be added to $M$). If $|M| \geq n$, then print out $M$. If $M < n$, then create a set of vertices $S$ that has all vertices that are not in $M$. I can prove that $S$ is an independent set we need to find.Suppose that $S$ is not an independent set. That means there are two vertices $u, v \in S$ such that there is an edge $(u,v)$ in the given graph. However, that also means we can add $(u,v)$ to the matching $M$ (contradiction). Therefore, $S$ must be an independent set.It is easy to see that $|S| > 3n - 2|M| > 3n - 2n = n$, therefore $S$ is an independent set we need to find.
•  » » » » 6 months ago, # ^ |   0 awesome proof.
•  » » » » 6 months ago, # ^ |   +14 My solution for 1C/2E is in $O(TV)$。First put all the points into a set.When you read an edge, if its 2 endpoints are all in the set, put the edge into a vector and delete the 2 endpoints.In the end, if the size of the vector >= n, we can puts "Matching".If the number of remaining points >= n, we can puts "IndSet". So it's $O(V+E)$ per a query.
•  » » » » 6 months ago, # ^ |   0 Very nice. I was trying to figure out something similar but I was too stupid and also there is an Edmonds blossom algorithm, so I ended up coding that...On the other hand, when I was not able to clearly see all these things during the contest I could have ended up coding something very similar, yet incorrect, which resulted in some tle's and wa's among submissions. When I checked them, they seemed to do something that you described, so I don't regret.
•  » » » » 6 months ago, # ^ | ← Rev. 3 →   +1 As far as I know just use wiki ;)https://en.wikipedia.org/wiki/Matching_(graph_theory)#Maximum_matching
•  » » » » » 6 months ago, # ^ | ← Rev. 2 →   +1 xHm... (testing links syntax; seems there are bugs in processing brackets inside the link)
•  » » » » » » 6 months ago, # ^ |   -8 Use a href, Luke.
•  » » » » » 6 months ago, # ^ | ← Rev. 3 →   0 A Vietnamese competitive programmer gave me an article that presents an $O(\sqrt{V}E)$ algorithm for the maximum matching on general graph Gabow (2017)
 » 6 months ago, # |   +3 is div2 E is a coloring problem(vertice coloring and edge coloring)?
 » 6 months ago, # |   +1 When you solve A for arbitrary x and y and then check the actual constraints and wonder what is wrong with you.
 » 6 months ago, # |   +3 DP state for Div2 F?
•  » » 6 months ago, # ^ |   +1 Yes. It's in $O\left(n^5\right)$. $f(x1,y1,x2,y2)$ mean the answer to the range $(x1,y1)$ to $(x2,y2)$.Use memorized search to maintain the answer.
•  » » » 6 months ago, # ^ |   -16 Can you please explain how O(n^5) is passing? If we directly calculate then it's 3*10^8 computations. The more complicated calculation would be — (50*(51)/2)^2 (states) * 2 * ~25 (dividing each rectangle into two rectangles, horizontally and vertically.This is easily crossing 10^7 computations and almost touching 10^8. Generally, 1 second means less than 10^7 computations, right? (Help me out with that please, could never get a proper idea)With reference to my submission — FOn a side note, hot to make comments look pretty? I know there's bold and italics but for example, how to use superscript?
 » 6 months ago, # |   0 I was in despair until I found that $O(n^5)$ solution can pass 2F/1D.
 » 6 months ago, # | ← Rev. 3 →   +2
•  » » 6 months ago, # ^ |   +18 How this two problems are connected?
•  » » » 6 months ago, # ^ |   0 Hi sir may I know if the random solution in Div1 F will fst?
•  » » » » 6 months ago, # ^ |   -28 There exist random solutions which will get OK.
•  » » » » » 6 months ago, # ^ |   0 OK Thanks.
•  » » » » » 6 months ago, # ^ |   +8 Do you mean something provable?
•  » » » » » » 6 months ago, # ^ |   -138 No, I mean that we don't know how to create tests against some randoms
•  » » » » » » » 6 months ago, # ^ |   +105 Waaaaaaat, even this shit? :/ 58013316
•  » » » » » » » » 6 months ago, # ^ |   0 Well, OK, I've just started wondering if it is simply correct... Any ideas anybody?
•  » » » » » » » » » 6 months ago, # ^ |   -43 I try to use the same way as this guy, But I sometimes Get WrongAnser. So this solution is incorrect.
•  » » » » » » » » » 6 months ago, # ^ |   0 Sound reasoning
•  » » » » » » » 6 months ago, # ^ |   +23 0.5 to counter some determine but slow and still let random pass!
•  » » » » » » » » 6 months ago, # ^ | ← Rev. 2 →   0 The problem isn't the TL, you can pass with $100$ ms (58034608). If you want to avoid this kind of incident, then the best way is to not have F in the contest.
•  » » » » » » 6 months ago, # ^ | ← Rev. 4 →   +10 I am wrong.
•  » » » » » » » 6 months ago, # ^ |   +10 Imo $(20~choose~10)$, but I'm not sure.
•  » » » 6 months ago, # ^ |   +15 The only one difference is that in one, you are asking to find matching, and in other, you have to find set with at least one edge from each node. These are quite similar things. In fact, solution of how to find matching is described in the editorial of Gold Experience.
•  » » » » 6 months ago, # ^ |   +19 Gold Experience, you say?
•  » » » » 6 months ago, # ^ |   -56 Ok, you are totally crazy, don't see a point in continuing this conversation
 » 6 months ago, # |   +11 Hope pretests were strong else RIP
 » 6 months ago, # |   0 Div1C одна из лучших задач за последнее время, спасибо автору.
 » 6 months ago, # |   0 Validator 'val.exe' returns exit code 3 [FAIL Expected integer, but "#include" found (stdin, line 1)] close (what???)
 » 6 months ago, # |   +4 Will the random solution in Div1 F fst?58029804Hope it won't. :D
•  » » 6 months ago, # ^ |   +39 If this submission can be accepted, it's really a bad problem.
•  » » » 6 months ago, # ^ |   +30 It seems that it's already a bad problem.
•  » » » » 6 months ago, # ^ | ← Rev. 2 →   +11 well, this submission has got passed https://codeforces.com/contest/1198/submission/58013316
 » 6 months ago, # |   0 how to solve D, I wrote some stupid n^6 dp and thought it would pass, of course it did not pass
•  » » 6 months ago, # ^ |   +17 Observation 1: An optimal solution exists by only painting squaresObservation 2: An optimal solution exists such that no two painting regions intersect, otherwise we can merge them into a bigger square.Thus we can do a naive dp using submatrix as states, divide horizontally or vertically for transferring.
•  » » » 6 months ago, # ^ |   0 Can you explain observation 1 a little bit please?
•  » » » » 6 months ago, # ^ |   0 If I paint a rectangle with size $w\times h(w>h)$, it costs $w$, if I paint $w\times w$ instead, it still costs $w$ and it won't be worse.
•  » » » » 6 months ago, # ^ |   0 If we paint a rectangle of size $n\times m$ where $n •  » » » » » 6 months ago, # ^ | 0 can you prove your observation using another argument like for a given construction can you provide a way to convert a rectangle submatrix to some subset of square submatrices while maintaining the same cost . i can't seem to prove both of your observations simultaneously using your argument , suppose i give you an optimal construction then i can choose larger side of a rectangle as a square and the total cost remains same and your observation1 is true but then we may have intersection between two regions and observation2 is not valid (I think we need to prove your observations in some other way ).Also you didn't use any of those observations in your code for div1D , main point was that we could divide horizantally or vertically a given submatrix , can you prove why this strategy gives optimal solution ? •  » » » » » » 6 months ago, # ^ | +8 otherwise we can merge them into a bigger square. •  » » » » » » » 6 months ago, # ^ | 0 ohk i understand it now(skipped that part :p).can you prove the main part, why dividing horizantally/vertically while transferring is optimal. •  » » » » » » » » 6 months ago, # ^ | 0 An optimal solution exists such that no two painting regions intersect Therefore it must be splittable. •  » » » » » » » » » 6 months ago, # ^ | 0 nice, i was trying to draw some counter example's but seem's i can't avoid both a horizantal cut & vertical cut simultaneously (except the whole rectangle ) inside a rectangle , such a strong statement. •  » » » » » » » » » 6 months ago, # ^ | +15 This conclusion is wrong, consider the following painting regions on a$9 \times 9$board:$\text{1 3 3 5}\\ \text{3 7 5 9}\\ \text{7 5 9 7}\\ \text{5 1 7 3}$What you actually need is that if the optimal solution is not splittable, then the projections of the regions onto the longer side cover the longer side, so the cost is at least its length, which is easily achievable (just take the whole grid as a painting region). •  » » 6 months ago, # ^ | +16$f[x1][y1][x2][y2]$denotes... Well, you know.When it is all white, it is$0$.$f[x1][y1][x2][y2]=\min(f[x1][y1][x2][i]+f[x1][i+1][x2][y2])$(Split it vertically)(Split it horizonally too)And paint a square with length$\min(x2-x1+1,y2-y1+1)$, then split it to two smaller rectangles.It is$O(n^5)$with small constant. •  » » » 6 months ago, # ^ | 0 What does "... Well, you know" mean? •  » » » » 6 months ago, # ^ | 0 The minimum cost to paint the rectangle with left lower corner$(x1,y1)$and right upper corner$(x2,y2)$to all white. •  » » » 6 months ago, # ^ | 0 I think it should be max(x2-x1+1, y2-y1+1). •  » » » » 6 months ago, # ^ | 0 Well, actually my solution is a little different to other solutions (including official solution). You mean using a square with length$\max(x2-x1+1,y2-y1+1)$to paint all the rectangle white, while I mean using a square with length$\min(x2-x1+1,y2-y1+1)$to paint only a part of the rectangle.The following picture describes my idea. •  » » 6 months ago, # ^ | 0 got AC with n^6 dp (code). Can someone hack my solution?  » 6 months ago, # | +1 how to solve div2 C? •  » » 6 months ago, # ^ | ← Rev. 5 → +4 You can have at most 2^k distinct elements, where k is (8 * I / n).If there are m distinct elements in the sound file, you need to reduce d = m - 2^k elements to fit onto the disk.Let cnts be an array that:index: nth small elementvalue: how many times it appears(We can use std::map to obtain such an array: counting with std::map, iterate over the map, collect its value part.)For i in [0..d], we change all the smallest i elements and the largest d - i elements, count how many element we changed, and the final answer is the smallest count. (That is, sum(cnts[1..i]) + sum(cnts[(m-(d-i)+1)..m])) (We can use prefix sum array to calculate the sum) •  » » » 6 months ago, # ^ | ← Rev. 2 → 0 you don't even need to use map to count, you can sort them and count number of elements each value. my_code •  » » » » 6 months ago, # ^ | 0 I think two pointers is enough :P  » 6 months ago, # | +249 A is the hardest problem among ABCDE :( •  » » 6 months ago, # ^ | +39 DSDSDASDSDDDS I CAN'T AGREE MORE.I wasted 40 minutes in total on A, misread it like two times and had some horrible bugs. On the contrary, I saw the ideas for B-E immediately. •  » » 6 months ago, # ^ | +12 Got hacked on A :( •  » » 6 months ago, # ^ | 0 maybe it's the hardest among ABCDEF :( •  » » » 6 months ago, # ^ | +25 My F failed, so I can't say that :( But it seems so. •  » » 6 months ago, # ^ | +6 The task is natural and simple but the instruction is not written "smoothly", so hard to understand.  » 6 months ago, # | ← Rev. 2 → -27 B is totally dump.Maybe I will never write Um_nik contest anymore.Now I am upset enough to give some bad words, but I just can't.The last time: B is dump. •  » » 6 months ago, # ^ | +16 Here you are.. •  » » » 6 months ago, # ^ | +7 B is actually frustrated because they didn't explain the test cases properlynot only I experienced this •  » » 6 months ago, # ^ | -7 B was grade 3 maths, I think it should be tagged with math* instead of geometry* and given 500 rating. •  » » 6 months ago, # ^ | +3 Maybe it's not the problem but it's you.  » 6 months ago, # | +17 Wow, another implementationforces round, so cool (no)(2).  » 6 months ago, # | +9 In Div1E if the grid was small enough, I believe it could be solved by bipartite matching(with the observation that it is always worth to choose an entire line or column). Is there a way to "normalize" the big bipartite graph and transform the task into flow problem or something similar? •  » » 6 months ago, # ^ | +8 You can compress the coordinates to get a grid that is essentially 100 by 100. The observation is that only the boundaries of the rectangles matter.  » 6 months ago, # | +107 Div1C and Div1E are so super standard, especially E  » 6 months ago, # | +1 how to solve div2 c?? •  » » 6 months ago, # ^ | +6 First you can note that the position of numbers doesn't matter. So think of a set of numbers (multiset) instead of array. It's because when we select$[l, r]$it will "influence" all numbers.So now we have to make all numbers in our set in range$[l, r]$. It means that when we select some$[l , r]$all numbers that are outside this range will change.So our answer for selected$[l, r]$is$ans = cnt[1] + cnt[2] + ... + cnt[l-1] + cnt[r+1] + cnt[r+2] ...$, where$cnt[i]$count of number$i$Now let's think what we have to do in our problem :D$ourTotalMemoryUsed = n*ceil(log2(K))$, where$K$— number of distinct elements$maxMemory = 8*I$$overallMemoryUsed \le maxMemory (overall memory should be less equal then max memory)n*ceil(log2(needK)) \le 8*I$$ceil(log2(needK)) \le 8*I/nneedK \le 2^{(8*I/n)}$That means that our result set should have less or equal then$2^{8*I/n}$distinct elements.Now let's select some$l$. Now we have to select such maximum$r$that number of distinct elements in that range will be less or equal then$needK$and our answer for selected$[l, r]$will be$n - (r - l + 1)$Why? Because elements outside this range will change.Now how can we calculate it? Iterate through all elements in our sorted array. It will be our$l$. Then using 2 pointers we can find max$r$, that number of distinct in range$[l,r]$will be less or equal then$needK$•  » » » 6 months ago, # ^ | 0 Could you take a look into my solution, it is what you said but do not pass 10th test :(https://codeforces.com/contest/1199/submission/58049925 •  » » » » 6 months ago, # ^ | 0 Increase R before entering your for loop.Otherwise you add cnt[b[R]] twice. Once in while, next time in for loop. •  » » » » » 6 months ago, # ^ | 0 aijey can you please tell me why the position of element doesn't matter ? •  » » » » » » 6 months ago, # ^ | ← Rev. 3 → +1 Any range you select, you should check all elements, whether they are in range, and change them if not.Example: 2 4 1 5 2 3 5. [3, 4]Checking a[1] = 2 -> changing...Checking a[2] = 4 -> in range(don't change)Checking a[3] = 1 -> changing...Checking a[4] = 5 -> changing...Checking a[5] = 2 -> changing...Checking a[6] = 3 -> in rangeChecking a[7] = 5 -> changing...So ans = 4. You can see, that any way you shuffle the array, the answer for [3,4] will be always 5UPD: a[5] isn't in range •  » » » » » » » 6 months ago, # ^ | 0 But can you please tell me why a[5] = 2 is in range . By the way thanks actually I misinterpreted the question . •  » » » » » » » » 6 months ago, # ^ | +1 Oh, it's not. Sorry)  » 6 months ago, # | +185  » 6 months ago, # | +3 What was hacking test for Div2 C/Div1 A ? •  » » 6 months ago, # ^ | ← Rev. 3 → 0 maybe 2^(I*8/n) is too big to exceed the range of int.(sorry, I made a mistake •  » » » 6 months ago, # ^ | 0 I * 8 / n •  » » » 6 months ago, # ^ | +44$I\le 10^8$... •  » » » » 6 months ago, # ^ | +22 I use 1<<((I * 8)/n) and get FST QwQ...this may be what memset0 means. •  » » » » » 6 months ago, # ^ | +15 Yes, thanks. •  » » 6 months ago, # ^ | +5 I wrote I=min(31,I),I=1<  » 6 months ago, # | +4 When can I resubmit? I have almost solve. I want test my new code. •  » » 6 months ago, # ^ | +1 After system testing  » 6 months ago, # | 0 Messed up problem A itself. Can somebody explain the logic now? •  » » 6 months ago, # ^ | 0 Iterate for whole array :Run two loops :for(int j=i-x;j=0;j++)for(int j=i+1;j<=i+y && j  » 6 months ago, # | +1 How to solve Div2-C? •  » » 6 months ago, # ^ | 0 From disk size and number of samples you calculate the available bits per sample. This determines the biggest difference from lowest to highest possible storagable value.Then you find among the input samples the biggest possible count of samples with a difference less than or equal to the above value. •  » » » 6 months ago, # ^ | +2 The problem statement is easy to misread. The number of bits needed is calculated based on the number of distinct values, not the range of the values. So you need to find the optimal range to clamp the values such that the number of distinct values after the clamp is small enough.  » 6 months ago, # | ← Rev. 2 → +1 Can someone please explain an online solution for DIV2-D?mango_lassi can u please share your approach? •  » » 6 months ago, # ^ | ← Rev. 2 → 0 What I tried to do was sort all people on the basis of the last change of type 1, with that change.Start iteration from last 2nd type change, and maintain 2 pointers, 1 on people array(sorted by last change), and other on the array holding 2nd type of events, maintain a maximum variable and update the final value of in-range people with maximum of (current value of that person, largest of x till now) and decrease pointers, continue....Edit:: Sorry didn't read "online" in your comment. •  » » 6 months ago, # ^ | +19 build a lazy propagation segment tree where the lazy values represent the value x in type 2 updates. A type 1 update would need to push down the lazy values from the root to the leaf, and then update the array value at the leaf. A type 2 update just sets the lazy value at the root. To push a lazy value of a node to its children, you update the lazy value of the children to the maximum of the node's lazy value and the child's lazy value, then set the node's lazy value to some garbage value which is at most 0. When querying for the value of one point, we push down the lazy values from the root to the leaf, and max the array value with the lazy value at the leaf.  » 6 months ago, # | 0 How's that even possible that O(n(x+y)) solution does not pass A? 58001554 •  » » 6 months ago, # ^ | +8 It's (s — x) in the 2nd loop i think, buddy! :D •  » » » 6 months ago, # ^ | ← Rev. 2 → +5 Oh god :( •  » » 6 months ago, # ^ | 0 You wrote in line$ for (intj=s-1$;$j>=j-x$&&$j>=0;--j)$j >= j — x instead s — xI think its the error  » 6 months ago, # | ← Rev. 2 → -10 Any ideas why it's TLE xd? 58001816 •  » » 6 months ago, # ^ | 0 Maybe its because array V is not global •  » » » 6 months ago, # ^ | -10 I think passing an argument to a function shouldn't affect complexity •  » » » » 6 months ago, # ^ | ← Rev. 3 → +3 If you send data without reference to function, the function will copy the value first. So complexity of each checking is$O(n)$. Sending reference as vector& and you will get AC. I think. •  » » » » » 6 months ago, # ^ | -10 Thanks bro  » 6 months ago, # | ← Rev. 2 → 0 For Div. 2 D, anybody has ideas about what is the 4th test case? Please share it :D  » 6 months ago, # | +63 Btw, F can't be solved in polynomial time for big integers. HintReduce to hypergraph 2-coloring.  » 6 months ago, # | +22 If Um_nik in panel AND you use Java, Run Virtual Contest at same time.  » 6 months ago, # | +10 Div. 2 C is a bad problem •  » » 6 months ago, # ^ | ← Rev. 2 → 0 Pretests are bad too. Nearly 1/3 fst.  » 6 months ago, # | 0 @Um_nik: Out of curiosity, question about F: If there is no prime that divides at least n-2 numbers, is it true that if there exists a solution then solution trying out completely random assignments will find one? •  » » 6 months ago, # ^ | -170 I don't know, tests were prepared by Burunduk1 •  » » 6 months ago, # ^ | 0 random assignments for me it's not obvious, what "random assignments" arei tried out "random shuffle + greedy assignments", on my tests it finds answer during first 100 tries. •  » » » 6 months ago, # ^ | 0 I meant simplest possible way, no greedy or whatever, just i-th number belongs to first group with prob 1/2 (all events independent) •  » » » » 6 months ago, # ^ | +9 Wow =) i even could not imagine so simple solution. It gets WA 46 with cutting by TL=0.5 seconds •  » » » » » 6 months ago, # ^ | ← Rev. 2 → 0 But does this test satisfy the assumption that no prime divides at least n-2 numbers? Because my solution that got accepted in contest 1) does some weird mumbo-jumbo, 2) tries some random assignments satisfying some.constraints determined by first part. However if there is no prime dividing >=n-2 numbers then my first part does nothing and second part is trying simplest possible random assignments as I described (and it got accepted as I said). It seemed fine to me as 3-edges are far less limiting than 2-edges and I still can't have a lot of them, but I didn't have any formal proof and was curious whether I am right. •  » » » » » » 6 months ago, # ^ | 0 does this test satisfy the assumption that no prime divides at least n-2 numbers? Hm... No. Moreover, it seems, none of tests, where random assignments fails, satisfies the assumption.You may investigate tests more precisely  » 6 months ago, # | +1 How to apply Segment tree in problem D? •  » » 6 months ago, # ^ | 0 Segment tree is overkill for this problem •  » » » 6 months ago, # ^ | 0 We know, but we dont know how to use it in this problem :/ •  » » » » 6 months ago, # ^ | 0 You can look at my code. I used segtree. •  » » » » » 6 months ago, # ^ | 0 Thank you. •  » » 6 months ago, # ^ | 0  » 6 months ago, # | 0 I'm gonna get my personal best rating until now!!  » 6 months ago, # | +11 hackforces! •  » » 6 months ago, # ^ | ← Rev. 2 → +14 Why the pretest is not strong?  » 6 months ago, # | 0 Div.2 C can be solved using binary search. •  » » 6 months ago, # ^ | 0 Yes! Here is my code : https://codeforces.com/contest/1199/submission/58018073 Techniques used : Sorting,Prefix Sums, Binary Search. Feel free to ask the doubts ! •  » » » 6 months ago, # ^ | 0 my solution is giving wrong answer on test 13 can u tell where i am wrrong •  » » » 6 months ago, # ^ | 0 Could you please explain the work of this line of your code ? ans = min(ans,pre[i-m]+suf[i+1]); •  » » » » 6 months ago, # ^ | 0 pre[x-1] is used to get the number of terms which are less than the term at x and suf[x+1] is used to get the number of terms which are more than x. Basically, I am calculating the number of element which are not in range [l:r] in constant time.  » 6 months ago, # | ← Rev. 2 → +72 Find the bug in code. Spoiler in edit history :( •  » » 6 months ago, # ^ | +69 You might fool systests but you can't fool me.Hacked :)  » 6 months ago, # | 0 Can someone explain me how to use segment tree in problem D(div 2) please •  » » 6 months ago, # ^ | 0 you don't need segment tree •  » » » 6 months ago, # ^ | 0 just read the events form end to start and try to solve it •  » » » » 6 months ago, # ^ | ← Rev. 2 → 0 Thanks.I know this solution, but we can solve it online using segment tree. •  » » » » » 6 months ago, # ^ | +1 https://codeforces.com/blog/entry/68775?#comment-531334also, "solve" instead of "solute" •  » » » » » » 6 months ago, # ^ | 0 Thank you •  » » » » » 6 months ago, # ^ | 0 use a lazy propagation seg tree with the max operator and with two change operations •  » » » » » » 6 months ago, # ^ | 0 Thank you •  » » 6 months ago, # ^ | ← Rev. 2 → 0 Here's my take on it: 58038546 (it uses a lazy segment tree implementation using pointers)  » 6 months ago, # | 0 Update ratings please!!!  » 6 months ago, # | ← Rev. 2 → +3 Just out of curiosity, can I get a count of how many solutions failed system tests for Div2C/Div1A?  » 6 months ago, # | +43 nobody:pretests:  » 6 months ago, # | +6 Somehow I didn't think$O(n^5)$could fit the time limit for D and tried to come up with an$O(n^4)$one. My idea is basically to only consider rectangle$(x_1, y_1, x_2, y_2)$where$x_1 = 0$or$y_1 = 0$. I don't know how to prove it formally though. Code •  » » 6 months ago, # ^ | +44 Hacked :) •  » » » 6 months ago, # ^ | +8 Great, thanks!  » 6 months ago, # | +3 can we solve C by Binary search ? •  » » 6 months ago, # ^ | ← Rev. 3 → +3 Yep! I solved it using binary search, first applying BS on the answer, which would be b/w 1 to cnt (cnt being the number of distinct numbers) and then another binary search nested in it to find the min number of changes needed to obtain that particular distinct element count. Here's a link to my solution div2C  » 6 months ago, # | +11 Correct me if I am wrong, But my Div2 D's solution passed the system test, without being right. Test Case:input41 2 3 422 10002 1Output 1 2 3 4Expected 1000 1000 1000 1000 •  » » 6 months ago, # ^ | 0 Yeah, it is incorrect, mine gives 1000 1000 1000 1000. And i was expecting the pretests to be strong, jokes on me :P.  » 6 months ago, # | +34  » 6 months ago, # | 0 Auto comment: topic has been updated by Um_nik (previous revision, new revision, compare).  » 6 months ago, # | 0 https://codeforces.com/contest/1199/submission/58037512 https://codeforces.com/contest/1199/submission/58025301 Two same solution one giving wrong answer and other being accepted. •  » » 6 months ago, # ^ | +7 One of the submissions was during the contest and the other was after the contest. The test case (Test 109) which the first submission failed on was added after the contest as part of uphacking, but is not used to judge submissions in the contest.  » 6 months ago, # | -16 Div2C: If there are exactly K distinct values in the array, then we need k=⌈log2K⌉ bits to store each value. As they talking about bits, I thought the distinct values are continuous (that's how bits work right?) . Am I the only one who faced this confusion? •  » » 6 months ago, # ^ | +8 Even the question talks about the range: We choose two integers l≤r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities. I thought every number from l to r (both inclusive) are represented by one of the bits. So the distinct values are contiguous. Did anyone else feel it ambiguous? •  » » » 6 months ago, # ^ | -10 Um_nik can you please look into this? I felt the question statement was confusing.As it says about K distinct values, but then it says about a range [l, r]. So I thought we can represent values [l, r] (contiguous) using the 'k' bits. But it turns out that we can use 'k' bits for non-contiguous values as well.In that case why did they talk about a range [l, r] and had confused the statement? •  » » » » 6 months ago, # ^ | ← Rev. 2 → +13 The range is necessary for the problem statement. If you can select arbitrary values to modify then you would greedily retain the K distinct values with the most occurrences. •  » » » 6 months ago, # ^ | +1 I thought the same thing. I should really read questions more carefully next time. •  » » » 6 months ago, # ^ | ← Rev. 2 → +3 If there are exactly K distinct values in the array, then we need k=⌈log2K⌉ bits to store each value.I was confused too. But after looking at it a second time, I think this means to compress with a dictionary.For example, if there are 3 different values 'A', 'D', 'K', and message M ['K', 'A', 'D'].'A' => 00'D' => 01'K' => 02M => [02, 00, 01]With a dictionary, values don't have to be continuous. •  » » 6 months ago, # ^ | 0 No it just means that if you had distinct values a1, a2, a3, .... an then you can describe each of them with ceil(log2n) bits. Example: if you know that you are given values 11, 12, 15, 257 then you don't need 9 bits to hold 257. Instead of it you can mapping 11 to (00), 12 to (01), 15 to (10) and 257 to (11). •  » » 6 months ago, # ^ | 0 I didn't completely understand the statment too.  » 6 months ago, # | 0 Is there anyone like me who didn't understand the problem statement of C?If you already got AC,then please share your idea.  » 6 months ago, # | ← Rev. 8 → +6 2D/1B solutionLet request time be it's order number.Let's keep two arrays: the first one will hold our values and the second one will hold the time for the last first type request (1 p x). Let's name them values and last_upd.Iterate over the requests.If it's first type request (1 p x), then values[p] = x; last_upd[p] = request_time;If it's second type request (2 x), then save it as pair (request_time, x) in the array second_type_requests.Right now there are the last values in the array values, which were changed by the first type requests. Let's find out which second type request can change this value. It goes without saying that the request_time of the second type request should be more than the request_time of the first type request. If such request is not alone, we should choose the one with the biggest value. We've reduced our task to finding maximum on suffix of the array second_type_requests. We can find it fast using the suffix_max_array.Time complexity is O(N + Q) •  » » 6 months ago, # ^ | +2 1A is 2C •  » » 6 months ago, # ^ | 0 Nice explanation! Thanks!  » 6 months ago, # | 0 Hi. Can anyone point out any optimization to improve my solution? https://codeforces.com/problemset/submission/1199/58040359 •  » » 6 months ago, # ^ | 0 Fast I/O makes a huge difference. You can check my submission and see my comments marking the optimizations at the beginning. Include those lines at the beginning of all of your submissions (or use scanf/printf) and your programs should run considerably faster.  » 6 months ago, # | 0 Can someone explain how to solve div1E? I realized that I need to somehow reduce the problem to flow, it is clear that you need to compress coordinate, but I'm apparently stupid and can't understand what kind of graph here you need to build. •  » » 6 months ago, # ^ | +21 Because the cost function is min(h, w), you can assume that all your actions are of two types only: paint whole row in white or paint whole column in white. Than we can say, that every black cell needs to be painted either from the corresponding row, either from the corresponding column. Let's create a bipartite graph. One half will be for the x coordinates, another one for the y coordinates. First lets assume that we don't compress the coordinates. We will add a single edge from ith row to jth column for each cell (i, j) which is black. Now you need to find the minimum vertex cover of this graph, because at least one of row/column needs to be painted. When you compress coordinates, every vertex will correspond to the range of columns/rows, and because of it will have a weight equal to the length of this range. Finding the minimum weighted vertex cover can be deduced to finding minimum cut of the network, where you add edges from source to each vertex of the first half and add edges from each vertex of the second half to the sink with with the capacities equal to their weights, and keep the original edges of the bipartite graph with the infinite capacities. •  » » 6 months ago, # ^ | ← Rev. 2 → +24 A similar version of this problem is "Given a$N \times N$grid containing white and black cells. In each operation one can color all black cells in a row or a column white. Determine the minimum number of operations required to turn all black cells into white".The solution is to construct a bipartite graph of$N$vertices on both sides, and for each black cells$(r, c)$we connect the$r$-th vertex on the left side to the$c$-th vertex on the right side. The minimum vertex cover of the resulting bipartite graph is the answer since each black cells is destroyed by the operation corresponding to the vertex which covers that edge.As for Div1 E, a similar bipartite graph$G = (X, Y)$can be constructed on the compressed coordinates. So the problem is to find the "minimum weighted vertex cover" on the graph, which is equivalent to the min-cut on the following flow graph: For each$x \in X$, connect$S \rightarrow x$with capacity$w_x$. For each$y \in Y$, connect$y \rightarrow T$with capacity$w_y$. For each edge$(x, y) \in G$, connect$x \rightarrow y$with capacity$\infty\$. See this article for detailed explanation.
 » 6 months ago, # | ← Rev. 3 →   +8 Solution for Div2 D without using segment tree.Observation: a later higher payoff will cancel all previous lower payoffs. a citizen's final balance is determined by the last change and the highest payoff after that. We go through events in reverse.Record a visited array for all citizen and the highest payoff.On event 1 p x:If the p-th citizen has been visited, then its balance has been changed later, pass.else, mark it as visited, update its balance to max(highest_payoff, x)On event 2 x:update highest_payoff to max(highest_payoff, x)It may be easier to understand by reading the code: 58038489
•  » » 6 months ago, # ^ |   0 Thank you , can you please also explain how to solve C ?
•  » » » 6 months ago, # ^ | ← Rev. 2 →   0 I tried, but found it hard to express this algorithm in English.https://codeforces.com/blog/entry/68775?#comment-531353Calculating sum(cnts[i..(i + 2^k - 1)]) may be more straightforward here.
 » 6 months ago, # |   +8 My submission58042687 on Div1 Cand58041401 on Div1 Fpassed the system test.Of course, they failed during the contest, but after I tried to do some voodoo programming, I finally managed to write some randomized sols that (I think) should not be passed, but they finally got accepted (almost TLE/WA).
•  » » 6 months ago, # ^ |   +29 -C
•  » » » 6 months ago, # ^ |   0 Nice, could you please find something for this: 58027618?
•  » » 6 months ago, # ^ |   +29 -F
 » 6 months ago, # |   +13 An interesting thing, cf predictor says that cnnfls_csy should get 583 pts, whilst he got only 296. Why is there such a difference?
•  » » 6 months ago, # ^ |   -36 https://codeforces.com/contest/1199/submission/58043340can someone tell me why it is giving wrong answer on test 13
•  » » » 6 months ago, # ^ |   +5 Try with this small test, the right answer is 3: 8 1 1 1 2 2 2 3 4 4 The array D will be: 2 3 1 2 
•  » » 6 months ago, # ^ |   +15 It says his previous rating was 1500, but that's wrong
•  » » » 6 months ago, # ^ |   +8 Ok, thanks!
 » 6 months ago, # | ← Rev. 2 →   0 someone please recommend some other problems like Div2 D where we can get answer without using segment tree?
•  » » 6 months ago, # ^ |   0 SQRT decomposition should work well
 » 6 months ago, # |   +1 Weak pretest, random algorithm bypassed, flood of fst.Good contest.
 » 6 months ago, # | ← Rev. 2 →   0 Is there an optional solution to solve Rectangle Painting 2 if cost is max(h, w) ?
 » 6 months ago, # | ← Rev. 2 →   0 all right
 » 6 months ago, # |   +463
•  » » 6 months ago, # ^ |   +38 The best today.
 » 6 months ago, # |   0 How to solve Div2-D without using segment tree?? (I tried to understand through comments but can't)
•  » » 6 months ago, # ^ |   0 My solutionYou can ask any questions if you have.
 » 6 months ago, # |   0 Can someone please help me on DIV2 problem C question. Let me know if my logic is correct:first find critical k <= min(n, 2^((8*I)/n)). Then sort the given array, and convert the array to its freq array i.e. if original array is 1, 2, 2, 3, 3, 4: change it to 1, 2, 2, 1 (each element in this new array represents the frequency of distinct elements in original array). Now original task is to minimize the number of changed elements, that is now equivalent to finding k-subarray with maximum sum in new array (using sliding window method in linear time), and then return new array size — max sum found.Am I missing something here? It is failing on 10th test case. Link to my soln:https://codeforces.com/contest/1199/submission/58049910
•  » » 6 months ago, # ^