### Rhodoks's blog

By Rhodoks, history, 3 weeks ago, Sorry for the late editorial. May this editorial help you. If you have questions, feel free to ask.

1711A - Perfect Permutation

hint1.
solution
code

1711B - Party

hint1.
hint2.
solution
code

1710A - Color the Picture

hint1.
hint2.
solution
code

1710B - Rain

hint1.
hint2.
hint3.
solution
code

1710C - XOR Triangle

hint1.
hint2.
solution
code

1710D - Recover the Tree

Thank dario2994, the key part of the proof is from him.

hint1
hint2
hint3
solution
code

1710E - Two Arrays

hint1.
hint2.
hint3.
solution
code Tutorial of Codeforces Round #810 (Div. 1) Tutorial of Codeforces Round #810 (Div. 2) Comments (130)
 » Auto comment: topic has been updated by Rhodoks (previous revision, new revision, compare).
 » Auto comment: topic has been updated by Rhodoks (previous revision, new revision, compare).
 » Thanks !
 » Thank you for the editorial!
 » You don't deserve the downvotes man :(
•  » » Upvoting this Blog can decrease his negative contribution.
•  » » » Let me be a snob and point out that this mathematically means it will become worse
•  » » The editorial is very well done, with hints/proofs of statements etc.
 » Why do we need to sort array in 1710 A? It works fine without it
•  » » it is just a way to give a valid answer. There may be better ways and in this problem you in fact do not need to implement it.
 » 3 weeks ago, # | ← Rev. 2 →   Great Div.1 D. If there had been a normal E, it would have been the best contest this month (so far).
 » Really liked the idea behind Div. 2 D, and the editorial explains it very well. Thanks!
•  » » Really? For me it reads like explaining nothing, just stating some formulars. I am lost in the second line.
•  » » » the same
 » Div2 B,I spent a full hour and a half thinking about the y=0 case and did it wrong！The torial is like a drop of holy water on my rusty brain feel so good~
 » Can someone explain in a little more detail Div 1 C?
 » Is there an error in Div2 D's solution? I think it should be pi−|xi−xj|>=aj−m
•  » » you are right. Thank you very much.I have fixed it.
 » Auto comment: topic has been updated by Rhodoks (previous revision, new revision, compare).
 » 3 weeks ago, # | ← Rev. 5 →   in Div2B,I think "if (degree[x[i]]%2==0 && degree[y[i]]%2==0)" need to replaced by "if((degree[x[i]]+ degree[y[i]])%2==0)"
•  » » They both work well.Exactly,"if (degree[x[i]] % 2==0 && degree[y[i]]%2==0)" is better.Because there are two cases if "degree[x[i]]+degree[y[i]] )%2==0",both x and y are even or odd.and when x and y are odd,we only need to remove one of them not two,So this should not be repeated.
•  » » » good
 » I don't understand the idea of difference array for Div2D. Can anyone explain in an easier way?
•  » » 3 weeks ago, # ^ | ← Rev. 4 →   a[i] can also be calculated in this way.Firstly,we make the contributions two arithmetic sequences.for example x=6,p=5that's 1,2,3,4,5 for [2,6] and 4,3,2,1 for [6,10].then we divided the contribution of an arithmetic sequence into two parts: b+k*ifor the above exampleswe add -1 for each position i [2,6],then increase each position i [2,6] by i.we add 11 for each position i [7,10],the decrease each position i [7,10] by i. now let's find two arrays for both the b and i.it's easy to calculate a 1D difference array.
•  » » » Thank you so much for your reply. However, if you loop through each position i in [2,6] or [7,10], will that not make your runtime O(n^2)?
•  » » » » well,for a arithmetic sequence,we divided its contribution into two parts.the first part is add a number b to an interval [l,r], you can use difference array to maintain it.the second part is add i for position i within interval [l,r] ,You can calculate how many times a position i is added,then it becomes add 1 to an interval [l,r]
•  » » » » » Oh, I think I see what you're saying now. Thank you!
•  » » » But isn't the constraint on range of x and p too high. How are u supposed to calculated difference array like this without iterating over the complete range atleast once?
•  » » » » just discretization.
 » my solution to problem B without using graphs--165604121
•  » » it's the same, as both solutions take operate on degree of nodes
 » 3 weeks ago, # | ← Rev. 2 →   Greedy proof for B:Assume we need to remove k people from the party in an optimum solution.Case 1 :Atleast one of these k people has odd number of friends. In this case, invite everyone except the person with an odd number of friends. If there is more than one such person, invite all except the one with the least unhappiness count.Case 2:All of these k people have even number of friends. In this case, there is at least one pair (i,j) among the k people such that i and j are friends. But then invite everyone except i and j. Since there are only m pairs of friends, we can iterate over all the pairs and find the minimum happiness count (a[i]+a[j]) where i and j have an even number of friends.Time complexity: O(m)Edit: Didn't care to look at the graph approach cause I hadn't learned it. Just found out that the editorial describes the same approach.
•  » » 3 weeks ago, # ^ | ← Rev. 3 →   I have one doubt in case 1. If we consider this situation n = 4, m = 3 a = [1,1,5,7] pairs = [(1,2),(1,4),(2,3)]Here we have two people with odd number of friends. This is case 1 according to you and we need to remove 3 to yield unhappiness count of 5. But we get minimum unhappiness count when we remove 1 and 2 to yield unhappiness count of 2. This means if we have odd number of friends, we need to check for both cases and the answer will be one with least unhappiness count. Correct me if I went wrong somewhere.
•  » » » You're right. What I meant is that we need to check for 2 cases in each iteration and update the answer in each iteration. In your example, since 1 and 2 have an even number of friends, we need to consider the case where we remove both 1 and 2. If the result is smaller than the previous answer, update it.Here is my code: 165598905 Ignore the comments in the code
•  » » » » The proof implies that the final answer will be either 1 guy with odd friends or 2 friends (both with even friends). It cannot be anything else.
•  » » » » » Thanks.Got it now.
 » Rhodoks orz
 » 3 weeks ago, # | ← Rev. 4 →   In Div 1C, there's an equivalent condition for the inequalities, $(a \oplus b) + (a \oplus c) = ((a \oplus b) \oplus (a \oplus c)) + 2 ((a \oplus b) \land (a \oplus c)) = (b \oplus c) + 2 ((a \oplus b) \land (a \oplus c)),$from the identity $x + y = (x \oplus y) + 2(x \land y)$.So, the three satisfy the triangle inequality iff $a \oplus b$, $b \oplus c$ and $c \oplus a$ are all pairwise non-disjoint.A digit DP solution from here is rather straightforward, 165666080.Here's $\land$ and $\oplus$ refer to bitwise AND and XOR respectively.
•  » » Yeah I did this. The editorial soln has $2^9$ constant factor but this soln took only $2^6$.
•  » » » Not really, you have atmost $8$ transitions from each state so it's more or less the same constant factor.
•  » » » » oops, sorry. you're right.
•  » » Can you please explain your dp states and transitions in brief?
•  » » » 3 weeks ago, # ^ | ← Rev. 6 →   Rather than calling the numbers $a, b, c$ let's call them $x_0, x_1, x_2$.We iterate from the highest bit to the lowest, so call the highest bit $0$.We have the states $(\text{idx}, \text{tight}, \text{cond})$ where $\text{idx}$ is the current bit we are on, $\text{tight}$, and $\text{cond}$ are bitmasks of size $3$. $\text{tight}_i$ is set if $x_i$ currently matches the input on the prefix $[0, \text{idx})$. $\text{cond}_i$ is set if $(x_i \oplus x_{i + 1}) \land (x_i \oplus x_{i - 1})$ (the indices are modulo $3$) has a bit set among the $[0, \text{idx})$ bits. I believe the transitions should be clear if you have experience with digit DP.We finally require that $\text{cond}_0, \text{cond}_1, \text{cond}_2$ are set so the final answer is $\sum_i \text{dp}(\lvert n\rvert, i, 7)$.
•  » » what does "all pairwise non disjoint" mean?
•  » » » By disjoint I mean that $x \land y = 0$, because if you view $x$ and $y$, as bitmasks/sets, $x \land y$ is the intersection of $x$ and $y$, and we say that sets $S$ and $T$ are disjoint if $S \cap T = \varnothing$.So $x, y, z$ being pairwise non-disjoint means that $x \land y$, $y \land z$ and $z \land x$ are all non-zero.
 » As a member of botswana community, i upvoted this post !!!!!!!!!!!!
 » Why does this solution give the wrong answer? http://pastebin.ubuntu.com/p/TrRV4gSKG5/
•  » » Just look at the solution in tutorial for problem A. It's much more simple.
•  » » 3 weeks ago, # ^ | ← Rev. 2 →   Your code fails when n = 8. Output is 8 7 6 5 4 3 2 1 but 6 % 3 = 0.i divides pi means that pi % i = 0, not the other way round.
 » For 1710B-Rain, why will the maximum position always be one of the centers? Can anybody help me to prove that?
•  » » A point $p$ which is between two center points, $L$ is all the points locates left to it and $R$ is all the points locates right to it. When we move $p$ from left to right, the rainfall from $L$ decrease(getting far away from it) or stay the same(some points is too far to give rainfall), the rainfall from $R$ increase or stay the same. In detail, the rainfall from $L$ decrease quickly first, then slowly(some points becomes too far) and the rainfall from $R$ increase slowly first, then fast(some points becomes close enough). That is the second derivative is always non-negative. So one of the center point must be the maximum point.
•  » » » This makes so much sense. Thanks a lot :)
 » Can someone help me understand the solution of div1B? I do not understand the implementation of the logic given in the editorial. What exactly is getIntersection() calculating?
•  » » 3 weeks ago, # ^ | ← Rev. 2 →   I just finished writing this huge post trying to explain it the best way I found. Hopefully it will answer some of your questions.
 » 3 weeks ago, # | ← Rev. 3 →   I struggled a lot with understanding how we found the intersections in 1710B — Rain without doing exhausting casework, so I decided to explain the math in the code for anyone else who also had a hard time. The post is a bit long, so I'll keep it in spoilers.We will keep track of the region $S$ such $\forall (x, p)\in S$ then there is no flood, i.e $p - |x - j| \geq a_j - m$, for all invalid positions $j$.Looking at the inequlity ( we can see that $(x,p)\in S \iff p\geq |x-h|+c$ (as mentioned in the editorial "One can check that the region of $(x,p)$ satisfying such an inequality is a quadrant rotated $45^\circ$ anticlockwise and translated.")So we will keep track of a function $f(x) = |x-h| + c$ to keep track of the region. Initially the center of a region described by point $j$ is $(j, a_j - m)$ so $h = j$, $c = a_j - m$ (notice that point $(h,c)$ is the center of such a region). Now $(x,p)\in S \iff p \geq f(x)$Now how can we interesect two regions $S_1,S_2$ described by $f_1, f_2$? We need to find the function $f_3 = \max(f_1, f_2)$. By visualizing (or doing a bit more complex case work) we can see that $S_3 = S_1 \cap S_2$ is also described by a similar function $f_3(x) = |x-h_3| + c_3$. How will we figure the parameters?If $x\leq \min(h_1,h_2)$ then $f_3(x) = \max(f_1, f_2) = \max(h_1 + c_1 - x, h_2 + c_2 - x) = t_x - x$ $(I)$ ($t_x$ is defined like that in the code).If $x\geq \max(h_1,h_2)$ then $f_3(x) = \max(f_1, f_2) = \max(c_1 - h_1 + x, c_2 - h_2 + x) = t_y + x$ $(II)$ (again $t_y$ is defined in the code).As we mentioned $f_3(x) = |x-h_3| + c_3$ so if $x\leq h_3$ then $f_3(x) = c_3 + h_3 - x$ and because of $(I)$, particularly looking for $x\leq \min(h_1, h_2, h_3)$ it must hold that $h_3 + c_3 = t_x$. Doing the same for $x\geq h_3$ because of $(II)$ we see that $c_3 - h_3 = t_y$. Solving the linear system we see that $(h_3,c_3) = \left(\frac{t_x-t_y}{2}, \frac{t_x + t_y}{2}\right)$. Which are the parameters for region $S_3$.In that way we can find the region $\displaystyle S = \bigcap_j S_j$ (going through all the invalid positions $j$) which was what we wanted to find. There might be an easier way but it is the most intuitive way I could find to understand the solution.
•  » » 3 weeks ago, # ^ | ← Rev. 2 → i think we can calculate intersection directly. suppose we have two region specified by $(a,b)$ and $(c,d)$ , and the intersection is $(x,y)$. then because the boundaries of regions are just line with slope 1 or -1, we can get \begin{align*} x + y = c + d \\ y - x = b - a \end{align*}which gives \begin{align*} x = (a-b+c+d)/2 \\ y = (b-a+c+d)/2 \end{align*}through my test, it seems the same as the one in tutorial code
•  » » » 3 weeks ago, # ^ | ← Rev. 7 →   That may be the case for some situations but the formulas are not correct every time. That is why my goal in the post was to skip "exhausting casework".Consider two points which sit on the same horizontal line, specifically $(a, b)$ and $(c,d) = (a, d)$. Then the formulas give the intersection as $(x,y) = \left(\frac{2c+d-b}{2}, \frac{b+d}{2}\right)$. We can see how this is not correct since the we can easily see that the center point should be $(x,y) = (a,b)$. (suppose $b>d$)Note: you might argue that we never intersect points with the same $x$ value, so with some constraint the problem may be solved the way you described but it is not whole picture I wanted to give.
•  » » » » oh, well, you are right. the main reason is that when one region totally contain another region, the intersection assumed in my equation is actually not exist.so it can not achieve "check whether point (xi,pi) belongs to such region", but just calculate some "ideal" intersection ... QAQ
 » Let's upvote this editorial to show some support to Rhodoks.
 » 3 weeks ago, # | ← Rev. 2 →   Just to add to Div2 C, it's called toroidal coloring because the parallel edges are connected by the modular relation. If you imagine, that will make a toroid.
 » Lets appreciate them for making this contest possible, humans make mistakes, thanks for the contest and editorial ❤️
 » Can someone help me figure out what's wrong with my submission for C 165672596 long explanation followsWhat my function does is that it divides all the elements in a by m. I then make me a list of all the elements in a that are greater than or equal to 2 and also find their sum. If this sum is less than the number of rows, return false. If it is equal to the number of rows, return true. Now we know that the number of rows we can use is greater than n. First go through all the elements of the list we created. If we can erase all the rows from the current color and still have our sum greater than or equal to n, we'll remove it. Else, we'll calculate the amount of rows from which we can safely remove from the color. This is basically the total amount of rows from that color minus 2. This amount is nonnegative because all the elements of the lest are greater than or equal to 2. We'll use as much of this leftover as possible and decrease sum and the current color by this leftover. At the very end, if the sum is equal to the number of rows, return true else return false.Just call this function twice(swap the row and col the second time). If at least 1 returns true, then the answer is Yes. Otherwise the answer is obviously No.As you can probably tell, this problem frustrated me a lot in contest. I'm wondering if anyone has a testcase or logic flaw that breaks my solution.
•  » » Take a look at Ticket 15920 from CF Stress for a counter example.
•  » » » Thanks a lot!
•  » » Here is a test-case: 5 5 4 15 10 10 10 First color fills 3 rows, while the rest each fill 2 rows. The YES solution is simple: use 3 + 2 = 5. However, your approach calculates a sum of 3 + 2 + 2 + 2 = 9. Then the first iteration of the leftover loop checks if 3 can be dropped, concluding that yes, 3 can be dropped to reduce the sum to 6, and it also changes the 3 to 0. However, without the 3, it is impossible to reach a target value of 5, since all that's left are 2s.Even aside from this, I don't feel like your approach of calculating leftovers and adjusting the sums accordingly is guaranteed to reach a correct solution, especially since the loop doesn't revisit a color (just a plain for loop). Have you actually proved anything about this approach?Instead, consider this alternative observation: if we overshoot the target, then for each color that covered more than 2 rows, we can decrease how many rows it covers (don't implement this, just think). If you keep reducing the problem in this manner, what are the possible outcomes? Is there some state that can't be reduced in this manner, but still overshoots? Once you characterize this state, you should be able to figure out when such a state can lead to a YES and when it will lead to a NO.
•  » » » You beat me to it.
•  » » » yeah, thanks. It's obvious to me now that a constructive solution like mine would be harder to make work.
•  » » Say your list is [3,2,2,2] and you are trying to make 5. You algorithm will take 1 out of the 1st element, and report 'No'?
•  » » » I like how we both thought of literally the exact same counterexample
 » Is there a proof of Hint 2 from XOR Triangle Editorial ? a XOR b <= a + b
•  » » For each bit, XOR is the plus modulo $2$ which is less or equal to plus.
 » In div 2 problem c my logic is same as given in this editorial but still it shows wrong answer on test 8 . Here's my solution https://codeforces.cc/contest/1711/submission/165574557 Please help!!!
•  » » Oh, your ll is just long but not long long.So it will overflow.
 » wow, the relation between div2D and region intersections is beyond my thought, interesting.
 » To be honest, apart from Div. 1 E, this is a really great round. The questions are really well-thought.Thank you for this round.
 » Question not that related to this round: Was problem difficulty rating system different in the past? I found lot of problems that have very high difficulty rating for it's difficulty. Some of them are from like 10 years ago, but some of them like this one is from 3 years ago.
•  » » Well I dont know if the rating system was different or not but my guess is that codeforces had fewer number of participants back then so many questions had less number of accepted submissions so their rating seems to be inflated, also a lot of time due to weak pretests a lot of successful submissions during the contest fail the system test, when this happens the rating of that particular question gets inflated as successful submissions during the contest really goes down.
 » i like the problems a lot ty <3
 » 3 weeks ago, # | ← Rev. 4 →   The editorial of Div2B (1711B) is a little misleading: If $y \geq 1$, then only deleting one vertex with odd degree would have been enough.If $y = 0$, then the parity of the edges at the end is determined only by the number of edges whose both endpoints are deleted. In particular, there must be at least two adjacent vertices deleted with even degree. In particular, specifying the conditions of $y \geq 1$ and $y = 0$ (which are mutually exclusive conditions) suggests that these are two mutually exclusive cases to consider, i.e., if $y \geq 1$, we should only consider the odd degrees for removal, while the removal of adjacent vertices with even degree should only be considered when $y = 0$. But this is false, since even when $y \geq 1$, it is not enough to consider only the odd vertices, and the optimal solution may require the removal of two adjacent even vertices instead. My suggestion would be to remove all mention of $x$ and $y$ (since their values are irrelevant for the algorithm design), and instead phrase these "cases" as options to consider (the I/O explanation in the problem also refers to them as options), with a brief note of why it's sufficient to only consider these two options: the other options not considered are the removal of a single even person only (which doesn't fix the total degree parity) or the removal of some superset of one of these two options (odd + some set, or even + even + some set).
•  » » well said
•  » » 3 weeks ago, # ^ | ← Rev. 2 →   Well, what I want to express is that, if you have an answer: If $y \geq 1$, you can get a not worse (but may not be the best) answer by only deleting one odd degree vertex of the $y$ vertices. So you do not need to consider it except when $(x,y)=(0,1)$. If $y = 0$, you can get a not worse (but may not be the best) answer by only deleting two adjacent even-degree vertices. So you do not need to consider it except when $(x,y)=(2,0)$ and they are neighbours. So, If we want to find the best answer, we only need to consider such two cases as I said. And if you think what I express here is easier to understand, I will modify it.
 » cough it's totally not because I suck at graphs that I ruined my ratings this round cough it shouldn't be violent cough
 » if m is even why the answer is zero ? cannot there be present a friend who is not connected to a friend ?
•  » » Because there is already even number of cakes so it's optimal to invite everyone
 » c is a brilliant problem...
 » 3 weeks ago, # | ← Rev. 6 →   A different solution to Div1 D:$Construct(L,R)$ is a function that finds the edges in the component of [L,R] ([L,R] is connected).You can construct as follows:Let $z$ be the largest number satisfies $z  » 3 weeks ago, # | ← Rev. 2 → I get stuck proving only stripe pattern make all cell to have at least 3 neighbors. (Div.2 C)Is there a easy way to prove it? •  » » It must be stripe pattern.In a row or a column.like this: 1 1 1 1 2 2 2 2 2 2 2 2 1 1 1 1 or 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 Prove:We can proof by contradiction. If there is someting like this: 1 1 1 1 1 1 2 2 2 2 2 2 It is not beautiful picture, because the "1" in row$2$column$2$only has$1$neighbor.similarly, this sort of picture is not beautiful: 1 1 2 2 1 1 2 2 1 2 2 2 1 2 2 2  •  » » In other words, if the picture is not a stripe, there must be a place which has$2$neighbors with different colors.neighbors with different colors are blacken.1 1 1 11 1 2 22 2 2 2Node that the lenth / width of the stripes mush be bigger than$2$. •  » » » thank's for your reply.i proved this by different way!we can generalize "non stripe pattern" as a "(stripe pattern) — (hole)" when hole is not stripe.and there is a two case. holes appear in first column. no hole appears in first column. 1st case ex)xxxxxx001000 <- 1 in this column is bad010000110011010001(x is color which is not 1 (possibly 0))then-> there exists always bad color 1 in column which color 1 is appear for the first time.2nd case ex)xxxxxx111111111111010000 <- some 0 in this column is bad110011010001then-> there exists always bad color 0 in column which color 0 is appear for the first time.and this model include all possible region -> proved!  » 3 weeks ago, # | ← Rev. 2 → oH mine gods, Sparky_Master_WCH1226 are the goodest in contributon rateing agan. thakns for you suppot sar.  » 3 weeks ago, # | ← Rev. 3 → D2DDamn. This getIntersection magic is the one I wouldn've thought about. You can do it simpler. Just maintain the minimum height current point should have to "cover" all the things on the left of it. It is a very simple dp.Then calculate the same for right and check for each point whether it satisfies both left and right.  » 3 weeks ago, # | ← Rev. 2 → In the problem B,we always can delete a edge to get a legal state. I think that "if(degree[x[i]]%2==0&°ree[y[i]]%2==0)" can be annotated. This is my test Your text to link here...for(int i=1;i<=m;i++) /*if(degree[x[i]]%2==0&°ree[y[i]]%2==0)*/ ans = min(ans,unhappy[x[i]]+unhappy[y[i]]);  •  » » We can't delete an edge. We have to remove a vertex. •  » » » If m%2==0 ,the status is legal. We can delete two vertices of an edge."Let's consider the case where m is odd only, since if m is even the answer is 0."  » Hi everyone. I request you to check my submission: https://codeforces.cc/contest/1711/submission/165852284 It is giving correct answer in my console but wrong answer on codeforces. •  » » It was a segmentation error. Thanks to anyone who checked. •  » » » for(int i = 1; i<=n; i++) cin >> arr[i]; for(int i = 0; i  » 3 weeks ago, # | ← Rev. 4 → Hello. Can someone tell me please, why this solution for C is WA?https://codeforces.cc/contest/1711/submission/165895290Thank you! •  » » Take a look at Ticket 15939 from CF Stress for a counter example. •  » » » I already found mistake, but anyway thank you!  » 3 weeks ago, # | ← Rev. 2 → Getting MLE in Problem B (Party). My solutionHow to resolve? •  » » move the FastIO out of the while loop https://codeforces.cc/contest/1711/submission/165923134 •  » » » Thanks a lot ! Btw what fast input output really did there? to give a mle ... can you explain :). •  » » » » tbh i have no idea lol sorry :(. •  » » » » » It's fine ..you solved my problem anyways.  » For 1710A-Color the Picture, shouldn't$\sum_{i=1}^{n} \lfloor \frac{a_{i}}{m} \rfloor$instead be$\sum_{i=1}^{k} \lfloor \frac{a_{i}}{m} \rfloor$? Also, I don't understand why if, when$n$is even,$\sum_{i=1}^{k} \lfloor \frac{a_{i}}{m} \rfloor \geq n$is sufficient. What if every$a_{i}$was a single row? Don't you still check if you can make the sum using at least$2$from each? It should be the sum of every$\lfloor \frac{a_{i}}{m} \rfloor$that is at least$2$. •  » » You are right, It is$k$and I forget to mention skipping those$a_i < 2*m$.  » 2 weeks ago, # | ← Rev. 2 → I solved Div1B in incredibly ugly way using segment tree. It was good exercise though. •  » » I also tried an approach with a seg tree but couldn't figure it out. If you have time, could you please explain how you did it? •  » » » 2 weeks ago, # ^ | ← Rev. 2 → Let$T(x)$be the total accumulation at position$x$. We can compute a bunch of intervals$[l_{i},r_{i})$and pairs of integers$(a_{i},b_{i})$such that for all$x\in[l_{i},r_{i})$,$T(x)=a_{i}x+b_{i}$using prefix sum technique. If we let$f_{i}=\max_{x\in [l_{i},r_{i})} a_{i}x+b_{i}$then it is obvious that we will get$f_{i}$either at$x=l_{i}$or$x=r_{i} - 1$. Now we want to consider the case when we can erase the$j$th rain. After we erase the rain, if we let$W_{j}(v)$be the total accumulation of the position$v$if we erase$j$th rains, then:$ W_{j}(v) = \begin{cases} T(v) & \text{if } v \lt x_{j} - p_{j} \\ T(v) - v - p_{j} + x_{j} & \text{if } x_{j} - p_{j} \le v \lt x_{j} \\ T(v) + v - p_{j} - x_{j} & \text{if } x_{j} \le v \lt x_{j} + p_{j} \\ T(v) & \text {if } x_{j} + p_{j} \le v \\ \end{cases} $Notice, that for every$i$,$\max_{v\in [l_{i},r_{i})} W_{j}(v)$will also be achieved at either$v=l_{i}$or$v=r_{i}-1$. Thus, all we have to do is compute the maximum of$W_{j}(v)$for all$v\in [l_{i},r_{i})$for each$i$using segment tree and compare the maximum with$m$. (Forgive me for terrible explanation because it is quite difficult to explain in plain English which is not my mother tongue) •  » » » » That was a really good explanation, thanks a lot!  »  » 2 weeks ago, # | ← Rev. 2 → .  » I was having hard time figuring out the editorial soln for Div2D/Div1B. So this is what I came up with.First we figure out all the$a_i$values as stated in the editorial. We will only consider all the$x$values for which$a_{x} > m$. Call them critical points. Take a look at the$i$-th flood. We will check it's left and right side separately. For it to fix any point$j$to it's left (that is$j < x_i$), this must be true:$a_j - (p_i - |x_i - j|) \leq m\Rightarrow a_j - j - m \leq p_i - x_i$. Deletion of$i$-th flood must satisfy this for all critical points to it's left. Here we can keep prefix maximum for$a_j - j - m$for all critical points and compare that with the R.H.S.We can get similar equation for the right half. It's$a_j + j - m \leq p_i + x_i$. This can be checked by keeping suffix maximums for all critical points.Overall the solution will be$\mathcal{O}(n\log{}n)$. One note for implementation, it's easier to check the two equations for all relevant points (even ones with$a_x <= m$) instead of just the critical ones. For points with$a_x <= m$define their L.H.S of the two above equations to be$-\infty$and it will be fine. Here is my submission.  » In div1C, can anyone explain how the transitions are taking place? What is m and how does it decide tmpmask1 and tmpmask2? •  » »$m$is the$i$-th bit of$a,b,c$. For example, when$m=(101)_2$then$a_i=1,b_i=0,c_i=1$.First, you should check if$m$is valid for the current state. If$cnt$will let$a,b,c$exceed the upper bound you should "continue".Then$tmpmask2$is whether it will reach the upper bound ($0$is yes while$1$is no).$tmpmask1$is whether it satisfies the conditions we mention in the editorial ($1$is yes while$0$is no).  » The editorial of 1E says: If we consider the initial bipartite graph, it's easy to see that we only need to check whether$(1,1)$is in all maximum matchings of the initial graph, becuase the maximum matching remains unchanged in the other$999$parts. (And it mistakes "because" for "becuase".)I think it's not obvious (probably because I'm too foolish), so I try to prove it. We need to prove If we want to get a maximum matching of the new graph, we can just copy a maximum matching of the initial graph$1000$times. If$(1,1)$belongs to all the maximum matchings of the initial graph, and we want to get a maximum matching of the new graph with a copy of$(1,1)$removed, we can just remove a copy of$(1,1)$from the maximum matching of the new graph we get above. The main idea of my proof is to prove that there exists no augmenting path in the two matchings we get above. To prove this, we assume that there exist an augmenting path, and we try to make it contains no more than one copy of any vertices. Then we show that this path is an augmenting path of the maximum matching of the initial graph or the initial graph without$(1,1)$.Sorry for not writing the whole proof down here, but my poor English doesn't allow me to do that.However, since the editorial said "it's easy to see", I believe there is a much cleverer and shorter proof. But I'm not able to come up with it. If anyone knows the proof, please teach me. Thanks.  » And the editorial says For the maximum independent set without the initial cell, you just need to remove it when it is in$I$. Note that if$da_{va}=da_{va-1}$or$db_{vb}=db_{vb-1}$($(va,vb)$is the starting cell), this strategy may not give the correct result for a certain$(i,j)$. I don't know whether it can always give the correct maximum independent set.I'm too lazy to write the proof for why it's correct if$(va,vb)$doesn't meet this condition, but it's not hard to prove.  » Can anyone explain me Question B — Rain. I'm unable to understand the editorial. •  » » Which part do you need to explain? Difference and prefix sum? Or the calculation of region? •  » » » Please explain calculation of region part? •  » » » » First, the maximum of$a$can always be achieved at the center of a certain rain. So if for the center position of any rain$j$,$a_j \leq m$then we know it is valid.If$a_j > m$then if erasing rain$i$can make position$j$valid,$p_i−|x_i−j| \geq a_j−m$must hold. Let's see what such a region is like.$p_i−|x_i−j| \geq a_j−m \iff |x_i-j| \leq p_i+m-a_j$where$m-a_j$is known constant for a certain$j$. So point$(x_i,p_i)$should be in such a region:$-p_i-C_1 \leq x_i-C_2 \leq p_i + C_1$Which is the translation of region$-p_i \leq x_i \leq p_i$, like: ..*********... ...*******.... ....*****..... .....***...... ......*....... Multiple such regions' intersection still holds such structure, and it can be easily calculated. I think UUUnmei's picture shows it clearly.You can refer to my getIntersection function which uses a way of rotation (rotate 45° clockwise and take the maximum of$x,y\$ then rotate them back) to calculate it.
•  » » » » » So much thanks for this wonderful explanation.
 » What topic should know first to understand the solving approach/ solution of problem D:Rain?
•  » » I think you need to understand difference and prefix sum. You can refer to this link.In this problem, you need a "second difference" and calculate it after discretization.
 » Can someone help me understand 165556433 for Div1 B?Specifically, What do a and b in the struct event represent?
 » Well, so finally Rhodoks' contribution turns positive again. That is a fair result at last anyway. Congratulations again, and also %%% CCOrz.
 » 10 days ago, # | ← Rev. 4 →   explanation for Q2.... party//basically we have two ways and the ans will be min from both of those cases..... //one way could be finding the point having odd connections and remove that..... //another way could be deleting 1 member in such a way that deleting it causes min unhappiness value.
 » can any one help me with last test case in B problem I think the answer must be 1