By Vladithur, history, 3 months ago,

Hope you liked the problems!

(from thanhchauns2) Before the round starts

1768A - Greatest Convex

Author: thanhchauns2

Hints
Tutorial
Solution
Feedback

1768B - Quick Sort

Hints
Tutorial
Solution
Feedback

1768C - Elemental Decompress

Author: thanhchauns2

Hints
Tutorial
Solution
Yet another better solution
Feedback

1768D - Lucky Permutation

Hints
Tutorial
Solution
Feedback

1768E - Partial Sorting

Author: thanhchauns2

Hints
Tutorial
Solution
Feedback

1768F - Wonderful Jump

Hints
Tutorial
Solution
Shorter solution (tfg)
Feedback
• +237

 » 3 months ago, # |   +100 From SPyofgame during the contest:
•  » » 3 months ago, # ^ | ← Rev. 2 →   +2 yeah, bro
 » 3 months ago, # | ← Rev. 2 →   +8 First time ranked top100 in div2. Hope for no FST!Update: It's frustrating that I always get downvoted and don't know the reason
•  » » 3 months ago, # ^ |   0 Why so many downvotes? This is bully!
•  » » » 3 months ago, # ^ |   -58 maybe because the information is irrelevant to this blog? keep your achievements to yourself.
•  » » 3 months ago, # ^ |   -10 There are only $2$ hacks for problem C in today's contest. The pretest is really strong!
 » 3 months ago, # |   +88 Permutation Forces !
 » 3 months ago, # |   +8 Delivered so fast..
 » 3 months ago, # |   +33 2023 should not be a permutation
 » 3 months ago, # |   0 love the fast editorial
 » 3 months ago, # |   0 I got the idea for C but not able to implement it. :-)..
•  » » 3 months ago, # ^ |   +3 mee too
 » 3 months ago, # | ← Rev. 3 →   -21 Can anybody help me to figure why this code is not accepted??? https://codeforces.com/contest/1768/submission/188117185
•  » » 3 months ago, # ^ |   +9 Do not paste the code in the comment.
•  » » » 3 months ago, # ^ |   +3 ok thanks to indicate I have removed the code
•  » » 3 months ago, # ^ |   0 Write codes in spoiler or only provide the link as you have provided here, as it becomes quite difficult to read this way
•  » » » 3 months ago, # ^ |   +7 ok I will see to it from next time
•  » » 3 months ago, # ^ | ← Rev. 2 →   +1 Although pasting code directly is awful, I've checked your code in the link. In fact, the most part of your code is right except one point: when doing m1[*it1]=*it2; you need to check if (*it1>*it2). If not, there's no solution because max(p[i],q[i]) will be *it2.
•  » » » 3 months ago, # ^ |   +1 ok!!!!!!!! Right I will think harder next time to not miss something like this
 » 3 months ago, # |   +43 You know what it feels like when you finish E when there're only 10 sec left but fail to submit the code before the last second?
•  » » 3 months ago, # ^ |   0 dude same, i was literally about to finish it, rip 2250
•  » » 3 months ago, # ^ |   0 Not my first time actually :3
•  » » 3 months ago, # ^ |   +3 Sorry, never solved D.:(
 » 3 months ago, # | ← Rev. 2 →   0 Amazing , was very curious for fast tutorial especially for Problem C.
 » 3 months ago, # | ← Rev. 2 →   0 Hi guys! although the editorial they've provided is great! still if you want a video format editorial you can find it here
 » 3 months ago, # |   0 PermutationForces?)
 » 3 months ago, # |   +12 "it took me 2 minutes to actually prove the solution"and it took me probably a minute and a half (may be inaccurate) to find out that $k! + (k-1)! = (k-1)!(k+1)$ and the rest of the proof is just factoradic blah blah
 » 3 months ago, # |   +3 i submitted 6 unsuccessful attempts so i lost 300 points in the contest? if there is a maximum amount u can lose, how much is it?
•  » » 3 months ago, # ^ | ← Rev. 2 →   +11 No matter how many times you submit for a problem, you get at least 30% of points if you solved it finally.
•  » » 3 months ago, # ^ | ← Rev. 2 →   +3 If you have wrong submission for problem $X$ you will get 50 points less then you usually would on that problem.If you have few wrong submissions on a problem you didn't solve, you won't lose any points.
 » 3 months ago, # |   0 what the F... solution ?
 » 3 months ago, # | ← Rev. 2 →   0 Why so tight TL on E.
•  » » 3 months ago, # ^ |   +11 You can calculate the inverses of factorials more efficiently by calculating them from n to 0.
•  » » » 3 months ago, # ^ |   0 OK! thanks
 » 3 months ago, # |   +13 Actually there's O(n) solution for C. We don't need to do any sorting. We can just count the occurence of 1-n and let occ[i]= the times i appeared in array a[]. if there's some occ[i]>2 there's no answer. Then we build two list more[] and less[]. We iterate for i from 1 to n, if occ[i]==0 we add it to less[], if occ[i]==2 we add it to more[]. since 0<=occ[i]<=2, the size of more[] and less[] will be equal. then we iterate for more[i] and less[i] reversely, if some more[i]
•  » » 3 months ago, # ^ |   0 Yah nice solution :3
 » 3 months ago, # |   +1 It's a well know fact that n — cycles is the minimum number of swaps to get 1, 2, ..., n.Can someone explains me this ? and where is this well know ?
•  » » 3 months ago, # ^ |   +2 each cycle of length $l$ needs $l-1$ swaps to be sorted, you can try it yourself
 » 3 months ago, # |   0 Thank for the fast tutorial!
 » 3 months ago, # |   +9 nice E...stuck in case f=2 too longgg...
 » 3 months ago, # |   0 codeforces!
 » 3 months ago, # | ← Rev. 3 →   0 I can’t understand the part of the proof(problem C) on why i*2 is contradiction. Can someone brief it and add some examples
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 I was confused, see the editorial "after sorting" is mentioned then it is true.Proof:if there is some index a[i]
•  » » » 3 months ago, # ^ |   0 Can you explain the approach?..I am a newbie.
•  » » » » 3 months ago, # ^ | ← Rev. 4 →   0 There is Two conditions for answer to not exist. First is if an element is present more than 2 times. Note: an element should appear exactly 2 times in final answer. Suppose if there is an element in array A that is present 3 times, then already we would placed two elements and there wont be 3rd element to place here. And the second condition is mentioned by me in above comment. So if neither of the condition satisfy, then there is answer so "YES". Now how to construct the answer is the question. We will take 2nd test case mentioned in the problem for example i.e.55 3 4 2 5So make 2 arrays p and q and place a element in p if the same element is already not present p as you cant place 2 same elements in p or q which wont be a permutationso p: 5 3 4 2 _q: _ _ _ _ 5so in both array p and q, all 1 to 5 should be presentso you will have each element of count 2. i.e. there will be two 1's, two 2's, two 3's and so on.... . [5 3 4 2 5] these element are already present so you would have remaining is [1,1,2,3,4] Now you have placed some elements in p and q, now traverse from highest to lowest element in p and place next biggest number that is not placed yet in q. So, for 5 in p, place 4. for 4 in p, place 3. for 3 in p, place 2. for 2 in p, place 1, similarly do the same for q. So for 5 in q, place 1.p 5 3 4 2 1q 4 2 3 1 5So this is the answer. Hope I have helped. This problem actually a lot more implementation specific.
•  » » » » » 3 months ago, # ^ |   0 Can you pls explain me how greedy aproach is working after filling array P and Q P 5 3 4 2 _ Q _ _ _ _ 5and then iterating from 0 to n if p[i] is empty then put the missing maximum element of P in P[i] or if Q[i] is empty then put the missing maximum element of Q in Q[i].
•  » » » » » 3 months ago, # ^ |   0 Thank you I got it now.Here is my explaination. Why we put the maximum missing element in p or q. suppose array a = [4, 2, 7, 10, 10, 1, 6, 6, 9, 9]. if there is a permutation of n numbers then if one number got repeated then it will replace 1 number in order to get repeated. Here in this example 10, 9, 6 replaced 3, 5, 8 in order to get repeated.After sorting the array vector> V in decreasing order V = 1 -> 5, 2 -> 1, 4 -> 0, 6 -> 8, 6 -> 9, 7 -> 2, 9 -> 6, 9 -> 7, 10 -> 3, 10 -> 4.then filling the array P and Q as a = 4 2 7 10 10 1 9 9 6 6 p = 4 2 7 10 __ 1 9 _ 6 _q = _ _ _ __ 10 _ _ 9 _ 6In second step Traversing in V from i = 0 to n-1, if we attached V[i].first it to p, find the biggest number that did not appear in q and attach to q, vice versa.Here is the reason why the biggest number that did not appear in p or q if a number got repeated so to make a valid permutation a smaller number must be replaced. Here repeated numbers are 10, 9, 6 or to fill the empty space by a small number which is 8, 5, 3. so it will make the valid permutations. biggest repeated number got replaced by biggest number which did not appear.
 » 3 months ago, # |   +73 F is so fantastic! It's hard to solve, but not hard to understand the solution.
 » 3 months ago, # |   0 Can we see pretest after the contest. This submission failed pretest 2: Link
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16674 from CF Stress for a counter example.
•  » » 3 months ago, # ^ |   0 Pretest 2 is every combination possible for $n \leq 5$, you can write a code then generate pretest 2 yourself.
 » 3 months ago, # | ← Rev. 2 →   0 I'm looking for problem like today problem D and C. Specially problems on arrays that can be transformed into problems on graph.Example 1 : You want to obtains array b from array a with some specific operationExample 2 : You want to obtains array a and b from array c with some specific operationExample 3 : optimizing or computing something on an array after some operation (This turns out to be somewhat related to paths on a graph ...)In almost all the solutions we need to build some graph with specific edges. I don't know how to tackle that kind of problems.
 » 3 months ago, # |   +25 F let me feel :F D let me feel :D
 » 3 months ago, # |   0 Problem C : Video Editorial Solution : link : https://youtu.be/d7Mb6pB4WKU
 » 3 months ago, # | ← Rev. 2 →   0 I got o(n) for C lolol. 188093045nvm its o(nlogn)
•  » » 3 months ago, # ^ |   0 sort(putP.rbegin(), putP.rend()) It is minimum O(n logn)
•  » » 3 months ago, # ^ |   0 No comments
 » 3 months ago, # | ← Rev. 3 →   +13 Since I didn't implement, please point out if I did anything wrong on F, or if my approach would TLE.After the monotonic stack observation, it should be possible to use a kinetic tournament on quadratics to handle cases with $min(a_i,\ldots, a_j)=a_i$ and li-chao tree or another kinetic tournament otherwise. The time complexity would be $O(n2^{\alpha(n)}\log^2(n))$.
 » 3 months ago, # |   0 I cannot understand the editorial of Problem C, which says there are (i — 2)*2 + 2 numbers. (there can be a repetition of numbers in p and q) also, why is this a contradiction?
•  » » 3 months ago, # ^ |   0 What do you mean by "there can be a repetition of numbers in p and q"? $p$ and $q$ are permutations, they can't have any repeated numbers (although the same numbers that appear in $p$ also appear in $q$ since they are both permutations from $1$ to $n$).
•  » » 3 months ago, # ^ | ← Rev. 4 →   0 I was also confused, see the editorial "after sorting" is mentioned then it is true. Completely forget the proof that is in editorial. I will explain it.Proof:if there is some index a[i]
 » 3 months ago, # |   0 In the editorial of problem E, when calculating the intersection for f(p)<=2, the sum should be sum(i=0...n) instead of sum(i=1...n). Please fix it
•  » » 3 months ago, # ^ |   0 Yes it is, I fixed the editorial.
 » 3 months ago, # |   +8 I had a slightly different $O(n)$ 188071468 from the one given for Problem C.
 » 3 months ago, # |   +8 No CHT solution for F? That's very interesting.
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 It is possible to use it to solve the second case, but you'll have to squeeze it into the tight ML.
 » 3 months ago, # |   0 It is a well know fact that n−cycles is the minimum number of swaps needed to get the permutation 1,2,3,…,n from our initial one (in other words, to sort it).Can anyone Please provide me the material where i can see this tutorial and learn . Thank You!!.
•  » » 3 months ago, # ^ |   0 Someone mentioned it. Each cycle of length $l$ needs $l - 1$ swaps to sort.
•  » » » 3 months ago, # ^ |   0 Thanks, i got it now .
 » 3 months ago, # |   0 Can anyone explain E in a simpler way ? I am having a hard time understanding the editorial..
•  » » 3 months ago, # ^ |   0 I modified it a little bit, maybe you'll find it easier to read.
 » 3 months ago, # |   0 Ugh my solution to C FST'd due to TLE can someone tell me why :(( https://codeforces.com/contest/1768/submission/188118022
•  » » 3 months ago, # ^ |   +1 Here is the reason -> https://codeforces.com/blog/entry/48793
•  » » » 3 months ago, # ^ |   +1 :((((( oh no I didn't know
•  » » » » 3 months ago, # ^ | ← Rev. 2 →   0 Well, U know it now.
 » 3 months ago, # |   0 Is it possible for you to make a report on the channels that download solutions on YouTube during the contest? Very thanks.<3
 » 3 months ago, # |   0 Maybe I missed something, but why there is O(n*sqrt(n)) with [n, n-1, n-2, ..., 1] array? Or any similar.
•  » » 3 months ago, # ^ |   +10 In this subcase, $a_j < \sqrt{A}$.
•  » » 3 months ago, # ^ |   +10 I think this time aj is smaller than sqrtA, consider all the cases of such j, the total compexity of the j with same value will not exceed n, so the overall complexity will not exceed..nsqrtA sorry my poor english
 » 3 months ago, # |   0 What will be the expected rating of the first 3 questions?
 » 3 months ago, # |   0 ⌊n−w+k−1⌋/kcould you please eplain me why we add K-1 with n-w ? .
•  » » 3 months ago, # ^ |   +3 so as to do the ceil operation otherwise it's by default floor operation as the integer division truncates anything after the decimal point
 » 3 months ago, # |   0 I'm having a hard time trying to understand the intersection formula for $f(p) \le 2$ from E's editorial. Can you please proofread the 'sketch and calculation' spoiler and fix some mistakes/typos?
•  » » 3 months ago, # ^ |   0 I modified it a little bit, maybe you'll find it easier to read.
•  » » » 3 months ago, # ^ |   0 I mean I read for example this sentence:In the last $n$ numbers there are $n$ numbers in range $[n+1,2n]$, we have used $1$ numbers for the first $n$ numbers. There are $C^n_{2n-1} \cdot n!$ cases.I think you wanted to write:In the last $2n$ numbers there are $n-1$ numbers in range $[n+1,2n]$, we have used $1$ numbers for the first $n$ numbers.And if this is the case, then I don't really understand the $C^n_{2n-1} \cdot n!$ formula.
•  » » » » 3 months ago, # ^ | ← Rev. 2 →   0 No, there are $n$ numbers, not $n - 1$. Since we used $1$ number to fill in the first $n$ numbers, there are only $2n-1$ options to choose for the last $n$ numbers, since they must be in range $[n + 1, 3n]$. I think the $n!$ part is easy to understand.Edit: okay I think I spotted the wrong thing, it is fixed.
•  » » » » » 3 months ago, # ^ |   +4 Ok, I see the interval in the third case was fixed. Now I get it. Thanks!I still want to add something, maybe someone finds it helpful. I don't find the $n!$ parts easy to understand as they are right now in the editorial, I find them a bit unnatural if not just 'wrongly' explained. The third case actually counts the number of ways to fill the last $n$ positions. What are the other two cases counting exactly, including the $n!$ 's, explained with words?This is how I would split it, each part counting one third of the positions: Take $n-i$ elements from $[1, n]$ and $i$ from $[n+1, 2n]$. This makes $n$ elements for first $n$ positions, and we take all the rearrangements. This is $C^{n-i}_n \cdot C^i_n \cdot n!$ As you explained, we need $n$ numbers in the range $[n+1, 3n]$ for the last $n$ positions, but $i$ of them were already used in the first $n$ positions, so we only have $2n-i$ left to choose from. Also, we can rearrange them. This is $C^n_{2n-i} \cdot n!$ The first $n$ and last $n$ positions are filled. The rest are the center $n$ positions. Rearrange them freely. This is just $n!$
•  » » » » » » 3 months ago, # ^ |   0 This is much clearer, thanks a lot.
•  » » » » » » 3 months ago, # ^ |   0 Kudo for lbm364dl, great explanation that help me a lot, take a long time to understand the editorial before found your comment.
•  » » » » » » 2 months ago, # ^ |   0 Sorry for late reply, suppose we have $n$ fixed indexes for the numbers in range $[1, n]$, then there are $n!$ cases for these numbers switching places with each other, the second and third $n!$ are exactly the same.In conclusion: The combinatorics is how we choose indexes for number in a range. The factorial is the number of cases after having fixed indexes. The third one is $n!$ because we already chose indexes for $n$ numbers out of $2n$.Anyway thank you for providing a much clearer explanation for this problem!
 » 3 months ago, # |   0 Problem C was a simple implementation problem I couldn't submit during the contest due to debugging issue, unlucky me but the contest was really great.Here's my submission for problem C — 188127408
 » 3 months ago, # |   0 Hi guys I have made editorial videos on A,B,C,D and uploaded on the channel — https://www.youtube.com/@GrindCoding, you can have a look and let me know if you like the explanation or please provide your valuable feedbacks.[D is currently being processed by youtube so might take a few mins to upload]
 » 3 months ago, # |   +14 There's no reason to make the mod not fixed as something like 1e9 + 7 in problem E. Any fft solution that passes that mod will pass for any other mod that you might ask for.
 » 3 months ago, # |   0 Can someone figure out the reason of runtime error in my code ? https://codeforces.com/contest/1768/submission/188111711
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16675 from CF Stress for a counter example.
 » 3 months ago, # |   0 Any idea why I got Wrong Answer instead of Runtime?During the contest in problem C I was getting WA so I tried to modify my solutions but now that the we can see the test cases it says "wrong output format Unexpected end of file — int32 expected"The thing is that I used an array of size $10^5$ instead of $2 \times 10^5$WA codeAC codeSo sad, with this modification I got AC with my first attempt :(
 » 3 months ago, # |   +4 In problem D,Turns out that we can easily calculate cycles′ if we know cycles:cycles′=cycles+1 if the vertices k and k+1 were in the same cycle in the initial graph, cycles′=cycles−1 otherwise.Can someone explain this???
•  » » 3 months ago, # ^ |   0 Here is the explanation
•  » » 3 months ago, # ^ |   0 You can understand it with Group Theory : explanation + code
 » 3 months ago, # |   0 I had a slightly different solution for C. Instead of sorting, you can use the upper_bound function to find the biggest number that hasnt appeared yet.
 » 3 months ago, # |   +16 thanks for the great round <3finally become pupil after 82 contest !!
 » 3 months ago, # |   0 Somebody please help me with my submission of problem C . https://codeforces.com/contest/1768/submission/188118465 Can't able to detect error.
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16676 from CF Stress for a counter example.
 » 3 months ago, # | ← Rev. 2 →   +2 Can someone explain for problem Lucky Permutation:Turns out that we can easily calculate cycles′ if we know cycles:cycles′= cycles +1 if the vertices k and k+1 were in the same cycle in the initial graph, cycles′= cycles −1 otherwise.
•  » » 3 months ago, # ^ |   +3 It's not easy to explain. I noticed this by using brute force on some small cases, but I can't prove it until the end of contest.
•  » » 3 months ago, # ^ | ← Rev. 4 →   +8 Cycles are for sort the array, we want 1 inversion. Let's say $i$ is connected with $x$ and ($i$+1) is connected with $y$.for inversion, we break the link from $i$ to $x$ and ($i$+1) to $y$ and make a new link from $i$ to $y$ and ($i$+1) to $x$. That's it, now if we analyse breaking and making link for $i$ and $i$+1 , we can see if $i$ and $i$+1 are from the same cycle they will brake the cycle and we have 2 cycles from the 1 cycle.If $i$ and $i$+1 in different cycle they will join together and make 1 cycle from joining 2 cycles.i hope it is understandable. graph
•  » » » 3 months ago, # ^ |   +1 Nice explanationThanks
 » 3 months ago, # |   0 "If we iterate from the smallest value to the top, there will be scenarios where all the remaining positions i will result in max(p[i],q[i])≥a[i] because you don't have enough smaller integers." This is written in the tutorial of problem C. Can anyone pls provide me a testcase where this scenario happens?
•  » » 3 months ago, # ^ |   0 5 5 2 2 1In this case, there are no enough place for 3,4,5 to put in.
•  » » » 3 months ago, # ^ |   0 But this test case anyways has no solution, provide a test case in which iterating from the smallest value give wrong answer.
 » 3 months ago, # |   0 can anyone pls tell me my mistake in problem C 188133899
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16677 from CF Stress for a counter example.
 » 3 months ago, # |   0 Why does my submission for C give TLE although it looks nLog(n).
•  » » 3 months ago, # ^ |   0 You are using the function upper_bound(something). Instead, use setname.upper_bound(int). The one you ar eusing can run O(n) sometimes and is bad. The one I mentioned uses binary search on sets and is much faster
 » 3 months ago, # |   0 can anyone please help me in figuring out why is this code of mine giving runtime error on test 7? tried enough not able to figure out.188129954
 » 3 months ago, # |   +10 F is cool!Is "1. min(ai...aj)>=A and 2. min(ai...aj)
•  » » 3 months ago, # ^ |   +10 Thanks! It's a typo, should be fixed now.
 » 3 months ago, # |   0 Got the idea for D after the contest lol
 » 3 months ago, # | ← Rev. 2 →   +16 Video Solutions for A-E
 » 3 months ago, # |   0 Nlog(n) code giving Tle for problem C please help! here is the code 188134958
•  » » 3 months ago, # ^ |   0 You are using the function upper_bound(something). Instead, use setname.upper_bound(int). The one you ar eusing can run O(n) sometimes and is bad. The one I mentioned uses binary search on sets and is much faster
•  » » » 3 months ago, # ^ |   0 In vector upper-bound is log(n) right? So why not in sets?
•  » » » » 3 months ago, # ^ |   0 It is not. The normal upper_bound() function works differently and at worst cases might iterate over the entire vector/set. But there is a special upper_bound() function for sets. Use setname.upper_bound(x). This is actual logn
•  » » » » » 3 months ago, # ^ |   0 Thanks a lot!
 » 3 months ago, # |   +3 A approach to Problem D using Group theory , Link To solution : 188139688If Permutation is not sorted, then it will contain some cycles, using Cycle Decomposition, we can break the Cycle of length k into** k – 1 Transpose** (Two Length cycles). If Identity transpose ex (1 3) is multiplied to itself ( 1 3 ) => it will cancel the effect , i.e. Elements have been placed to their correct respective location . So to make the permutation sorted, if there are k transpose, we can multiple k identity transpose, thus canceling out the effect and make them sit on their place. Note : sorted permutation means zero Inversion. And at last, do multiple any transpose of adjacent elements ( 3 4 ) or (1 2 ) or ( 5 6 ) , etc. to get One Extra Inversion . So, using DFS one can check for Cycles, find the length of cycles, cycle length – 1 is the transpose.So answer = total no of transpose from all cycles + 1 [ General case ] (for last extra One Inversion that is been added on top of sorted permutation).There is an edge case, what if one adjacent transpose is already present in one of the cycles, For example (1,2) is already present, and this contributes to only one Inversion, so we can take help of already present good transpose for this case note: we only need any One good transpose (adject transpose) . Let’s say good transpose is T , so first , in general case , we will multiply T with T to cancel out T and make permutation sorted, then again multiply T to add extra one inversion . So we can skip multiplication of T two(x2 ) times , because at last we want to use T as good transpose .T x T x T = T ( extra multiplication of T two times ) so we can subtract 2 operation from the general case answer . Ans = ( transpose + 1 ) – 2 [ when good transpose is already present in any of the cycles
 » 3 months ago, # |   0 Fucking shit I have been associated with a psychopath
 » 3 months ago, # |   0 Can somehelp me find the bug in my code.It's giving a wrong output on 7345th test case in test2.Here the link of my code-https://codeforces.com/contest/1768/submission/188142179
 » 3 months ago, # |   0 Isn't a case possible in D where number of cycles will remain same?
 » 3 months ago, # |   0 Why does my solution for C work when using stack but not unordered_map? Solution using unordered_map: Solution Solution using stack: Solution I am doing the same thing in both of them, except it works when I use stack instead of unordered_map. I see it gives wrong answer on test case 2, but I can't see the test case. Can someone give a test case that doesn't work for unordered_map? Thanks.
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 When you do it=extra.begin() when extra is an unordered_map, It's not guaranteed which element you will get, so probably it->second==true for both it you get for a certain i, which cause i appear 2 times in q.
•  » » » 3 months ago, # ^ |   0 But I'm taking the iterator, then erasing it before I get the next element. Shouldn't it delete the one I just used?
•  » » » » 3 months ago, # ^ |   +3 It's not "getting the one just used". It's "There might be multiple entries where it->second==true and you get 2 such entries for one x, then you put two x in q"
•  » » » » » 3 months ago, # ^ |   0 Can you give me an example of when this would happen? Thanks.
•  » » » » » » 3 months ago, # ^ |   0 It depends on the implementation of the iterator of unordered_map, so there's no determinate example.
•  » » » » » 3 months ago, # ^ |   0 But why would it work when I use a stack? Couldn't this also happen with a stack???
•  » » » » » » 3 months ago, # ^ |   0 Stack is an ordered data structure, you always get what you just put into it
•  » » » » » » » 3 months ago, # ^ |   0 So the two elements I get are guaranteed to be one in p, and one in q, right?
•  » » » » » » » » 3 months ago, # ^ |   +3 Yes
•  » » » » » » » » » 3 months ago, # ^ |   0 Thanks!!!
 » 3 months ago, # |   0 i am not improving._. may be i will improving
 » 3 months ago, # |   +1 The problemset should should have a tag for permutations, to practice for these kinds of problems.
 » 3 months ago, # |   0 Can someone explain why there is a +k in the final result of problem B, and not just (n-w)/k??
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 The reason is because we want to using ceiling division. If we used (n — w) / k, we would round down.
 » 3 months ago, # |   0 Permforces
 » 3 months ago, # |   0 C took me over an hour to implement...
 » 3 months ago, # | ← Rev. 2 →   0 Yet another $O(n)$ solution for C, but can be implemented more easily. Without the headers, it's only 700 B long with two for loops. solutionIterate from the smallest element to the largest. If a number $x$ appears only once at index $i$, then $p[i]=q[i]=x$. If it never appears, push it into a set. If it appears twice at indices $i$ and $j$, then remove any element $y$ from the set (I use a stack to implement). If the set is empty, then it's impossible; otherwise, $p[i]=q[j]=x$ and $p[j]=q[i]=y.$ If it appears more times, it's impossible. Iterating from the largest to the smallest is ok, too.
 » 3 months ago, # |   0 Is $O(n)$ solution for C too hard to think? Why not hack $O(n \log n)$ solutions?
 » 3 months ago, # |   0 How to prove in C that a[i]>I for all i ?
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 Consider this case: 5 1 1 2 3 5 The missing number here is 4, but the the 2nd element is 1, we cannot possibly construct this because if we put the missing element in the position, we'll get 1 4 2 3 5 4 1 2 3 5 Which is: 4 4 2 3 5However, if our array was like this: 1 3 3 4 5The missing element is 2, and we can construct an array like this: 1 2 3 4 5 1 3 2 4 5 Which results in the correct array!
•  » » » 3 months ago, # ^ |   0 Okay thanks for the help.
 » 3 months ago, # |   0 Hello Can anyone help why my code is giving wrong answer . Although it is not optimal ,but I am not getting where I am wrong . Pls help My submission ... Thanyou
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16678 from CF Stress for a counter example.
 » 3 months ago, # |   0 Can someone help explaining why in the editorial for F part 2.2 $min(a_i…a_j)=a_j$, iterating $i$ the way mentioned results in a total complexity of $O(N\sqrt{A})$ amortized ? Thanks in advance.
•  » » 3 months ago, # ^ |   0 for aj with the same value which is smaller than sqrtA, the total complexity will not exceed n.
 » 3 months ago, # |   0 Very frustrated to say I was able to solve C during the contest but due to the silly mistake of not printing extra space at the end of the first two outputs it gave the wrong answer. I left the solution unchecked, woke up in the morning, saw the test case failing, checked the code, found the silly mistake, and got AC.
 » 3 months ago, # |   0 I am not able to digest this fact . Consider there is some index that a[i]
 » 3 months ago, # |   0 B is more difficult for me than C..
 » 3 months ago, # |   0 Can someone help me to find the reason for TLE in Problem C for the submission 188102874But an AC for the submission 188105380
•  » » 3 months ago, # ^ |   0 use set.lower_bound(value) instead of set.lower_bound(start,end,value). The latter costs much more time.
•  » » » 3 months ago, # ^ |   0 Thanks!! Got Accepted now
•  » » 3 months ago, # ^ |   0 lower_bound on set is linear time, use set.lower_bound instead
•  » » » 3 months ago, # ^ |   0 Thanks
•  » » 3 months ago, # ^ |   0 At Line 157 use auto it = s.lower_bound(-q[i]); O(n^2)->O(nlogn)
•  » » » 3 months ago, # ^ |   0 ok thanks
 » 3 months ago, # |   0 The Submission 188119572 is Successfully Hacked but the Participant got points for the problem. How is This possible?
•  » » 3 months ago, # ^ |   0 It's hacked after contest ends
 » 3 months ago, # |   0 Problem C Eternal Decompress Video Editorial : Link: https://youtu.be/d7Mb6pB4WKU
 » 3 months ago, # |   +3 Concise solution for D: #include using namespace std; typedef long long ll; void solve() { ll n; cin >> n; vectorv(n); for (int i = 0; i < n; i++) cin >> v[i]; vectorcol(n); ll c = 1, comp = 0, pos = 0; for (int i = 0; i < n; i++) { if (col[i]) continue; pos = i; while (col[pos] == 0) { col[pos] = c; pos = v[pos] - 1; } comp++; c++; } ll ans = n - comp; for (int i = 0; i < n - 1; i++) { if (col[i] == col[i + 1]) { ans--; break; } } if (ans == n - comp) ans++; cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; } ~~~~~
 » 3 months ago, # |   0 I'm still curious about that "the minimum number of swaps" theory in problem D, is there any prove of that theory (blog or something)?
•  » » 3 months ago, # ^ |   0 the minimum number of swaps to sort is the classic problem, here is link
•  » » » 3 months ago, # ^ | ← Rev. 2 →   0 Thx :)
•  » » 3 months ago, # ^ |   0 Explanation : Link to comment Group theory has prove for this
 » 3 months ago, # |   0 About D, How they know the way to solve this problem during the contest? I mean is this a classical question ? Or they just figure out?
•  » » 3 months ago, # ^ |   0 i'm interesting of how could they just know whatever what is swaping in a cycle it will only minus 1,and whatever what is swaping between two cycle ,it must cost one movement to change it to the answer Do they prove it or just consider it should work
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 If someone had knowledge of Group Theory , then it is a clasical problem for them . Here is a explanation which might help : Link
 » 3 months ago, # |   0 can anyone tell what is wrong in my code I have used visited array for solving problem c https://codeforces.com/contest/1768/submission/188190772
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16679 from CF Stress for a counter example.
 » 3 months ago, # |   +13 Though my rating falls drastically in this contest. I love both the contest and the editorial. Keep organizing such contests Vladithur ❤️.
 » 3 months ago, # | ← Rev. 3 →   +3 Loved the contest, amazing problems, amazing editorial!!By the way, for problem C: 1768C — Elemental Decompress "There is also another way that you can skip testing if max(p[i],q[i])=a[i]) is correct." Another Way Here
 » 3 months ago, # |   0 How can i improve the time so i dont get TLE https://codeforces.com/contest/1768/submission/188205457
 » 3 months ago, # |   0 Can anyone explain or tell about resources where i can learn about counting the number of cycles in a directed graph. as a can't find it online. thanks
 » 3 months ago, # |   +2 I am just really glad this contest happened and would like to thank the authors of this round, as finally I could reach expert after this round.
 » 3 months ago, # |   0 can any one plzzz suggest a roadmap to be good at compeitive programming
 » 3 months ago, # |   0 At first ,i cnt not believe a so easily
 » 3 months ago, # |   0 Problem C Please someone help me with my code of Problem C I am not able to understand why there is a out of range error Help will be highly appreciated
•  » » 3 months ago, # ^ |   0 I can share you how I solved the problem. so basically I just kept the indexes of all the elements of the a with count of how much is number is occurring . since with some casework we can find that the number can occur only once or twice or none at all. so its just pairing the numbers that occur 2 times with the ones with 0 times. and place on the both arrays with what occurred one time at same place. since Code here#include "bits/stdc++.h" using namespace std; #define nl "\n" #define int long long using vi = vector; using pi = pair; using vp = vector; #ifdef TSUKI #include "bits/bug.hpp" #else #define dbg(...) #endif const int MXN = 2e5 + 10; const int INF = 1e18 + 10; const int MOD = 1e9 + 7; void solve() { int n; cin >> n; vi a(n), b(n), cnt(n + 1); map idx; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; cnt[a[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i] >= 3) { cout << "NO" << nl; return; } } sort(b.begin(), b.end()); for (int i = 0; i < n; i++) { if (b[i] < i + 1) { cout << "NO" << nl; return; } } cout << "YES\n"; vi occ1, occ2, occ0; for (int i = 0; i < n; i++) { idx[a[i]].push_back(i); } for (int i = n; i > 0; i--) { if (cnt[i] == 1) occ1.push_back(i); if (cnt[i] == 2) occ2.push_back(i); if (cnt[i] == 0) occ0.push_back(i); } for (int i = 1; i <= n; i++) { if (cnt[i] == 1) { int ind = idx[i][0]; a[ind] = b[ind] = i; } else if (cnt[i] == 2 ) { int indA = idx[i][0], indB = idx[i][1]; int e = occ0.back(); occ0.pop_back(); a[indA] = i; b[indA] = e; a[indB] = e; b[indB] = i; } } for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << nl; for (int i = 0; i < n; i++) {cout << b[i] << " ";} cout << nl; } signed main() { cin.tie(0); cout.tie(0) -> sync_with_stdio(0); int t; cin >> t; while (t--) { solve(); } }
•  » » 3 months ago, # ^ |   0 Take a look at Ticket 16680 from CF Stress for a counter example.
 » 3 months ago, # |   0 Can anyone tell why it is giving TLE (Div2 C) : https://codeforces.com/contest/1768/submission/188232190
 » 3 months ago, # |   +16 I love F!I think it is a quite good problem!
 » 3 months ago, # |   +8 In F tutorial,Is the "Just maintain the leftmost occurences" for the 2.1 cases a typo?Seems that it needs to maintain the rightmost occurences
•  » » 3 months ago, # ^ |   +3 Should be fixed now.
 » 3 months ago, # | ← Rev. 3 →   0 In problem D, Can we solve it by using cyclic sort technique? I am not able to figure it out that-> say by cyclic sort, we get n cycles as ans. Then how we will decide ans to be n+1 or n-1. What I know, by cyclic sort method, we get the minimum swaps to sort the array. Anyone please help
 » 3 months ago, # |   0 The front problem is too easy but the later problem is too difficult.
 » 3 months ago, # |   +13 Problem F is awesome. Couldn't solve it during the contest. After the contest, I looked at the "$a_i \le n$" hint from the editorial and solved it from there :) Sometimes just stressing a part of the statement can help you solve a problem :)
 » 3 months ago, # |   0 On problem D, cycles' = cycles + 1 if there are no adjacent connected components, not the opposite right?
 » 3 months ago, # |   +16 F is a really good problem, I thought $O(n\sqrt n)$ solution for a long time during the contest but still did not know how to solve it. But later I was amazed by the tutorial of problem F :)The facts to solve this problem are easy to understand and easy to prove, but it's really hard to find them :)
 » 3 months ago, # |   0 why we need to Compare min(ai…aj)⋅(j−i)2 with n⋅(j−i)?
 » 2 months ago, # |   0 Video solutions for A,B,Chttps://youtu.be/erOqAwknRJU
 » 7 weeks ago, # |   0 Need some help with a failed test case in problem C. 193152726
•  » » 7 weeks ago, # ^ |   0 Take a look at Ticket 16729 from CF Stress for a counter example.
 » 5 weeks ago, # |   0 Consider there is some index that a[i]