chromate00's blog

By chromate00, 15 months ago, In English
Rating Predictions

The editorial for each task is written by me, chromate00. I tried to explain each task with as much detail I could fit in. Brace yourselves, it is going to be LONG. Please don't try to open all spoilers at once, it lagged my browser. Also, I apologize for not telling you strongly enough to read every problem, almost every tester thought F1 is easy if you read it well...

Also, our fellow wuhudsm told me there will be another community contest in the Gym soon, details will be posted on https://mirror.codeforces.com/blog/entry/138706 shortly :catThink:

UPD: Added solution codes to all solutions.


2063A - Minimal Coprime

Author: chromate00

Hint
Editorial
Code (Python)

2063B - Subsequence Update

Author: Think_Only_Once

Hint
Editorial
Code (Python)

2063C - Remove Exactly Two

Author: chromate00

Hint
Big Hint
Editorial
Code (Python, Approach 1)

2063D - Game With Triangles

Author: wuhudsm (Original Idea) & chromate00 (Modified Idea)

Hint
Big Hint
Editorial
Code (C++)

2063E - Triangle Tree

Author: Think_Only_Once

Hint
Editorial
Code (C++)

2063F1 - Counting Is Not Fun (Easy Version)

Author: chromate00

Hint
Editorial
Code (C++)

2063F2 - Counting Is Not Fun (Hard Version)

Author: chromate00

Hint
Editorial
Code (C++)

UPD: People pointed out that the intended solution in the tutorial is overkill. Yes, I acknowledge this. Please look into the newly added alternative solution if you want a more elegant idea.

Editorial (Alternative)
Code (C++, by Mukundan314)
  • Vote: I like it
  • +229
  • Vote: I do not like it

| Write comment?
»
15 months ago, hide # |
 
Vote: I like it +220 Vote: I do not like it

Lightning fast! But I think your problems are not good enough for this historic round.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it -17 Vote: I do not like it

    Why do you believe this?

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it +4 Vote: I do not like it

      I explained my reasons in the comments above: everyone has high expectations for this game, But I think although there were no serious issues in this contest, the problem setter did not do anything very well. So lots of people (including me) doesn't like it.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +81 Vote: I do not like it

    Maybe 1024th round is more historic for a programmer.

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it +40 Vote: I do not like it

      You are right, but this is historic too! (Wish CodeForces can hold a better contest in the 1024th round!)

»
15 months ago, hide # |
Rev. 3  
Vote: I like it -33 Vote: I do not like it

Great blog!

  • »
    »
    15 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +46 Vote: I do not like it

    Because many people think Round $$$10^3$$$ should be made of awesome problems as an historic round. Clearly the problems aren't good enough.

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it +32 Vote: I do not like it

      Deeply sorry if you thought the tasks weren't awesome, I think we have different thoughts. I think most tasks were great.

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it +286 Vote: I do not like it

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it +46 Vote: I do not like it

        Well, you promised something epic, that might not be in a "normal div2 round".

        No hate, but imho normal div2 rounds usually have more interesting problems on positions A-D.

        Problem E's intended solution is really nice, but why did noone spot that it can be killed with normal small-to-large? To me E was also "read and immediately know how to solve"

        You managed to make interesting problem F, but intended solution using splay trees is also not in the list of epic things to me :/

        • »
          »
          »
          »
          »
          15 months ago, hide # ^ |
           
          Vote: I like it +5 Vote: I do not like it

          I did notice that E can be killed with small-to-large. I thought that the problem still is worth it, but it wasn't a surprise that it is "killed". I was thinking that depth-wise small to large is not a common topic for Div. 2.

          F has A LOT of solutions. Please don't be discouraged, any solution that works is a great solution for it.

          • »
            »
            »
            »
            »
            »
            15 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            I think my E just used common small to large which i implemented in at least 5 other cf problems back from the times when I was div2, though it's not the point

            Yeah, problem is still worth it, I'd be very happy to see such in div2 2 years ago when I was CM (as it was my fav trick then), but I'm speaking from a div1 perspective (perhaps, even if we're not rated auditory, we're still looking forward to 1000th round)

            For problem F you're right, just was discouraged after looking for a nice way to find the "outter" bracket pair for the last 20 minutes of the contest, and then seeing that in editorial...

            • »
              »
              »
              »
              »
              »
              »
              15 months ago, hide # ^ |
               
              Vote: I like it +11 Vote: I do not like it

              There are much cleaner ideas for F2.

              My solution was to maintain a segtree initially of all 0, then each time a bracket pair is added, you update each value in the interval by 1.

              Then, the left bound of the interval you are contained in is simply the first element to the left of your position that has a smaller value.

              • »
                »
                »
                »
                »
                »
                »
                »
                15 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                Yep, that's exactly what i thought of in the contest! Just didn't manage to finish it, as i had roughly 2 minutes left when i was done with that segment tree xD

                Thanks for explaining!

              • »
                »
                »
                »
                »
                »
                »
                »
                15 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                Log squared?

              • »
                »
                »
                »
                »
                »
                »
                »
                15 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                Could someone explain this (submission) for F2 please. It looks very elegant but I'm struggling to understand that backwards pairs processing.

            • »
              »
              »
              »
              »
              »
              »
              15 months ago, hide # ^ |
               
              Vote: I like it +18 Vote: I do not like it

              Also i have solution only with linked list and small-to-large

        • »
          »
          »
          »
          »
          15 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Hi, can you describe how are you calculating the answer using Problem's E small to large. I tried to keep an prefix sum array of frequency of depths, or something similar, but I don't know how I would keep it updated in the small to large.

          • »
            »
            »
            »
            »
            »
            15 months ago, hide # ^ |
             
            Vote: I like it +3 Vote: I do not like it

            Hi!

            I store arrays of frequency of depths, but with a trick:

            cnt[u][cnt[u].size() — k] = number of vertices in its subtree on the depth (k-1).

            Respectively, when we merge two children, say U and V, we iterate over this array for smaller one, say V is smaller:

            int du = cnt[u].size(), dv = cnt[v].size()
            int tot = /*size of subtree of u*/
            for(int i=1; i<=dv; ++i) {
               tot -= cnt[u][du-i];
               ans += tot*cnt[v][dv-i]*(2*i-1);
            }
            //now do the same with vertices in U on depth <= vertices in V
            tot = /*size of subtree of v*/
            for(int i=1; i<=dv; ++i) {
               ans += tot*cnt[u][du-i]*(2*i-1);
               tot -= cnt[v][dv-i];
            }
            
            • »
              »
              »
              »
              »
              »
              »
              15 months ago, hide # ^ |
              Rev. 2  
              Vote: I like it 0 Vote: I do not like it

              Could you explain the formula: tot*cnt[v][dv-i]*(2*i-1)? I don't get how we know that we get a nondegenerate triangles from this if we have set only one length

              I realised I was stupid cuz if you have a b sides and we dont know l you have b-a<l<a+b and if you do a+b-b+a+1-2 you get 2*a-1,bruuh

              • »
                »
                »
                »
                »
                »
                »
                »
                15 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                yes, exactly. The code fixes the smallest (out of the two) length and calculates the desired value.

            • »
              »
              »
              »
              »
              »
              »
              15 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              here u have , swapped by comparsion of dp[node].size(), but here dp[node] store information of all vertices at node subtree , on various depths thus , dp[node].size() indirectly gives node subtree depth , so how does time complexity is still NlogN ? By comparison of node subtree size , would have surely mainitned this time complexity

            • »
              »
              »
              »
              »
              »
              »
              14 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              Nice trick, was trying to solve it with small to large, but mine used a Fenwick tree and total complicity was O(n log**2), couldn't find better way to optimize it.

      • »
        »
        »
        »
        15 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it -95 Vote: I do not like it

        Yeah I wonder why they don't like speed forces for abc and bullshit geometry and greedy+ bullshit implementation for d, and an E which is just standard problem where u added also bullshit geometry to make it Cool but all u did was make a standard problem worse

        Even for a normal div2, this would've been a shitty contest, let alone round 1000

        • »
          »
          »
          »
          »
          15 months ago, hide # ^ |
           
          Vote: I like it +19 Vote: I do not like it

          cope

        • »
          »
          »
          »
          »
          15 months ago, hide # ^ |
           
          Vote: I like it +7 Vote: I do not like it

          the inclusion of "triangle" doesn't make a problem geometry. D and E has absolutely nothing to do with geometry unless you have not encountered the triangle inequality or area of a triangle formula, which you hopefully would've learned in middle school.

          • »
            »
            »
            »
            »
            »
            15 months ago, hide # ^ |
             
            Vote: I like it -15 Vote: I do not like it

            I get ur point, I honestly get it, they aren't geometry problem, they're geometry knowledge is at elementary school level, the point is when u use geometry terms, the problems automatically get shit, I promise if the problem didn't include anything about geometry, mainly using words that are Abt geometry, the problems were probably way more liked and better, also the last div2 b this holds, if the question was find a 4 element tuple with 2 equal elements such that the other two's absolute difference is less than 2*x, the problem would have had a lot more solves a lot faster, by using geometry words and phrases, u just make the problems more annoying, not better

            • »
              »
              »
              »
              »
              »
              »
              15 months ago, hide # ^ |
               
              Vote: I like it +34 Vote: I do not like it

              Actually, the problems are more motivated and intuitive if triangles are included, rather than a pure mathematical statement. Unless, of course, you can’t visualize a triangle.

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it +37 Vote: I do not like it

        Personally I thought the problems were all great, didn't get all of them but the main idea for CDE required some clever insights and were interesting to me. I also like that F was actually doable for div 2 contestants.

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it +32 Vote: I do not like it

        I thoroughly enjoyed the problems. This might be my favorite round ever.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I know dogshit about how to solve A i just implemented according to testcases

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

A was easy but B's pretest 2 destroyed me! I was absolutely shocked why it didn't work.

My Approach for B that didn't work
  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    obviously 1 2 2 1 is not going to work when l,r=2,3

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Suppose you have the following input

    Input

    Your approach would yield $$$1+1=2$$$, but this is not correct. You can't get to swap both $$$2$$$s with both $$$1$$$s. You wish to swap costly items in $$$a[l:r+1]$$$ with cheaper items.

    Observation
    Approach
»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great set of problems ! Clear description, nice test cases, no mistake ... Kuddos to all organizers. I will enjoy taking more time to solve D and E.

I have been stuck on C, but I don't understand why my submission got WA : 302435615. Could someone give me a hint ?

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    Consider this test:

    10
    8 9
    4 3
    4 2
    10 9
    1 9
    2 10
    2 5
    6 10
    5 7
    

    Your code outputs $$$4$$$, the correct answer is $$$5$$$.

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it +9 Vote: I do not like it

      My logic is correct, but my code is wrong. Because I modify the unordered_set I'm iterating on, the loop stops after the first iteration. I wasn't aware of this behavior ...

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      can you tell me why my code fails

      WA :302491912(https://mirror.codeforces.com/contest/2063/submission/302491912)

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        You are identifying the three highest degree nodes. It is not enough to find the best nodes. You can always think of an example where three highest degree nodes are connected, and a fourth with same degree is somewhere else in the tree. You should remove it, and one of the three, but by only searching for three nodes you might miss it.

»
15 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Can anyone help explain how my answer is wrong, I'm just searching for highest degree node, removing it, then finding the highest degree node again: 302462038

edit: I didn’t realize they can give the edges not in order, sorted levels then did same algo and ac

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I did terrible on this contest

On B, I took 2 subs to realize that I was checking [1,l+1] instead of [1,l].

My Prediction
»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

code for problem C

https://mirror.codeforces.com/contest/2063/submission/302448973

can anyone point out why it failed on test 4?

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can someone explain why I am getting WA: on my submission 302454358 in problem C. I am doing brute force. I am first greedily picking the first vertice and then removing it after picking second vertice.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Check this case

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      mine was passing on this as well don't know why it failed

      I guess the key thing was that the node with largest indegree and decrease the indegree by 1 for each neighbour and then found largest indegree overall and we are done

      • »
        »
        »
        »
        15 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it +1 Vote: I do not like it

        Consider that if you remove a vertex $$$v$$$ with maximum degree $$$d$$$ that contains at least two childs with degree $$$d$$$, you will get rid of the possibility to split the tree to $$$2\cdot d - 1$$$.

        Because if you remove $$$v$$$, you will get $$$d$$$ components, but your maximum degree will decrease to $$$d-1$$$. If you remove one of the childs of $$$v$$$ with degree $$$d$$$, you maintain the maximum degree as $$$d$$$.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

https://mirror.codeforces.com/contest/2063/submission/302459815

why this is wrong can someone explain ?

i have simply done the process told by the editorial and it is giving wa on 4

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    you choose the first vertex incorrectly. you take the vertex with the highest degree, but maybe if there are several such vertices, you take a non-optimal vertex.

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      how to find that given vertex with highest degree is optimal or not ?

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        you can search the 1st vertex and look for the maximum degree among the remaining ones using multiset. the asymptotics will be O(nlog(n)). that's what I did. or as it is written in the solution in point 2, search 2 vertices as the first one

»
15 months ago, hide # |
 
Vote: I like it -13 Vote: I do not like it

historical round, cool problems

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem C can be solved using DP without any observation, but the state transition is a little bit complicated.

»
15 months ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

Seems that F2 can be solved much more easily by solving reversely (with a disjoint set union to maintain the father-son relationship)

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    oh well, it was initially forcing online, and the coordinator thought offline is not too much easier. If offline makes it cleaner for you, you can solve it offline.

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

hi everyone! i understand each one of you might've had super high expectations since this was round #1000, i get it, but it's not right to belittle or humiliate other people just because they didn't exactly meet your super high expectations, right? i believe B and C were really nice tasks! also overall the round was enjoyable, the editorial also seems very informative, kudos to the authors + testers for this round. let's not get blinded by our subjective views and insult other people (by downvoting their blogs) who tried their best :) thanks

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For C I tried getting the maximum degree, adding that to the answer, removing that node and decreasing degree for each neighbour node and then getting the maximum degree again. Why does this fail, any counter case?

Code
  • »
    »
    15 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    there's a slight issue with this. let M be the maximum degree of a vertex present in the tree, and V be the set of all vertices with such degree M. there can be a case where you can remove a vertex from this set and still have another vertex of degree M present, which is the optimal way. however, in your case you aren't considering this and would remove a vertex which would affect the degrees of all remaining vertices in V, and hence, give a sub-optimal answer.

    for example: for a tree of 8 nodes with these edges: -

    1 2 1 3 1 4 2 5 2 6 3 7 3 8

    here you'd end up removing (1, 2) or (1, 3) which would give 4 components, but ideally you should remove (3, 2) and have 5 components.

    hope that helps

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ThankFully rating can not go below 0.....

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could someone give me a hint why my D solution gives WA3

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

There are nothing amazing question in this contest. And just for me , F1 is much more easier than E. Anyway , I'm glad to participate in this 1e3 round. May be it'll be better in 1024 round ? :)

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

[user:chromate00][user:MikeMirzayanov] I have submitted A in the contest. It is showing submitted in the official standings, however it is not showing submitted in the unofficial standings. Kindly rectify the situation. Submission- [submission:https://mirror.codeforces.com/contest/2063/submission/302363475]

»
15 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Editorial seems quite overkill for many of the problems, like binary search for D, and forest of splay trees for F. That being said I also solved F with link-cut tree lmao, though I'm not sure why the editorial doesn't mention that the forest of splay trees kinda just is a link-cut tree?

Anyway, very happy to AK and get rank 27 on such a special round. Screencast here for those who are interested.

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I don't get why my following logic failed in problem C,

My approach:

Initially ans = 1, and store the number of edges in an array sz.

First, find the vertex with most edges, let's say vertex u with sz[u] edges, then answer increase by sz[u]-1, then decrease sz[x] by 1 for all vertext adjacent to u. Also set sz[u]=0

Then repeat the process to get second vertex v. Then ans again increase by sz[v]-1

Submission:

https://mirror.codeforces.com/contest/2063/submission/302433943

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Consider this situation: the tree has five nodes —— 1-2-3-4-5

    Vertex 3 is one of the vertices with most edges, so possibly you tried to remove vertex 3. But the only optimal method is to remove vertex 2 and 4.

»
15 months ago, hide # |
Rev. 2  
Vote: I like it +11 Vote: I do not like it

despite doing horribly i think the problems are slightly better than your avg div 2 , and more balanced , not the quality i expected for the 1000th , still nice tho

edit : i havnt seen problem F , maybe it'll change my view of the contest

»
15 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

again messed up B and solved C before B. Also why downvotes, why do you think the problems aren't "awesome" ?

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F1 was predicted to be easier than D ?! :(

»
15 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

302471253 why does this not work for C?

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't know that experts can set most of the questions in a Div2 round before :|

The above is just my opinion, because after a while, I will become an expert :(

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

guys, did nobody solve C using dp/ dfs ?

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I have used Eular tour and dp rerooting to find out the answer if I remove the ith node.... and to find this I did something like this. At every node, I am updating the segment tree which stores the count of edges at each node. So as I am removing the ith node I am setting the value to 0 for the ith node and subtracting 1 from my child value and then I am finding the maximum edge of any node using the segment tree.... although this is very overkill for 1500 rated problem this is the solution which comes to my mind so it didn't waste time to think of any case work.

»
15 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

Here is my 2 post contest accepted submission for C..

302473806. (using inclusion exclusion property)

302476948 (initial approach with more operations)

can anybody hack these submissions??

During contest I guessed that, checking the first 10 or 20 nodes with higher in degree will do the work.. But I did not implement & I stuck with my initial solution.. Sed,, i missed as always...

  • »
    »
    15 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +2 Vote: I do not like it

    Actually, I think it's correct. We can see that the wrong solution fails when there are $$$3$$$ connected vertices with the same largest degree, and we can't pick the middle one as the first to remove. However, when there are $$$4$$$(or more) such vertices, we can pick the first one arbitrarily because it won't affect answer anymore. Therefore, checking 10 nodes(in fact, 3) should be enough.

»
15 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

I thought the problems were great, also I appreciate that F was doable even for div 2 participants. I found CDE all very interesting problems, but that's probably because they're at my level.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could anyone explain the 2 pointers approach in problem D please?

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I had the same direction as editorial for C but couldn't figure it out completely and then had to go back to DP because DP made sense to me quickly but the editorial approach needs some casework to be done.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It seems that problems F1 and F2 are very similar to problem E of the recent 997 round.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    We noticed this. F1 is similar to that E, but it is quite overkill to apply the same thinking process. Meanwhile, F2 is harder than that E. Therefore, we decided to keep both, for balance and completeness of problemset.

    or well I HOPED F1 will balance things but THEY DIDN'T READ

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem C : extreme brute force solution (302504107)

»
15 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

In the editorial of D, shouldn't it be concave instead of convex? Prefix sum of a decreasing sequence should be concave right?

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Depends on upwards or downwards. Usually in terms of optimization we call it convex in this situation.

    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it +5 Vote: I do not like it

      I think in both cases, it should be concave. The definition of a convex sequence says $$$2a_n \leq a_{n-1} + a_{n+1}$$$. Which translates to either $$$a_{n+1}-a_{n} \geq a_{n}-a_{n-1}$$$ or equivalently, $$$a_{n}-a_{n+1} \leq a_{n-1}-a_{n}$$$. This can be understood as follows, for an increasing sequence, the increments are increasing, or for a decreasing sequence, the decrements are decreasing. Intuitively, this also captures the U shape that is commonly associated with convex functions. The function in here, say $$$h(x) = g(x,k-x)$$$, is the opposite of what I described above. Hence I believe its more accurate to call it concave (it also follows the inverted U associated commonly with concave functions).

      • »
        »
        »
        »
        15 months ago, hide # ^ |
         
        Vote: I like it +6 Vote: I do not like it

        Even for the same graph people call it either convex upwards or concave downwards. It's just terminology difference

»
15 months ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

I actually used DP on trees and i don't know why but my solution is failing on Test case 2 C ripped my whole contest. missed D by 5 minutes.

here is my submission if someone would like to help 302414968

P.S.-I personally liked the contest problems

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F1 is easy. I solved it much earlier than D, the scoring distribution tells enough

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Overkilled E by narrow-mindedly focussing on a solution with treaps, then saw the editorial lol! Great round tho, befitting of the 1000th round, only wished it were a Div. 1 + 2 :)

»
15 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

The official F2 solution using splay tree was way more complicated than what I did so I decided to share it here.

Simple solution to F2 where the most complicated technique being used is max segtree: https://mirror.codeforces.com/contest/2063/submission/302526177

Equivilent quadratic solution: https://mirror.codeforces.com/contest/2063/submission/302525268

Note that

for(int i = l+1; i<r; i++) if(end[i] != -1){
    len[l]-=end[i]-i+1;
    i = end[i];
}

in the quadratic solution is equivilent to

for(int i = l+1; i<r; i++){
    len[l]-=len[i]+2;
}

in the fast solution. I also made len[i] include the start and end parenthesis in the fast solution but not in the slow (since it made it easier to code).

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

OK,but this got TLE and this got AC. I thought it's meaningless to make it TLE since their difference is only the way to save edge.You'd better try some other correct way to do your problem in order to avoid such terrible things.
Sorry for my poor english:(

»
15 months ago, hide # |
Rev. 2  
Vote: I like it +4 Vote: I do not like it

Good contest.

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Thanks for the round! I'm pretty happy with problem F, I managed to solve it with a normal segment tree and binary searching in it the smallest closing bracket to the left of the query.

Thanks for hosting codeforces 1000th round!!

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The test cases for C are not comprehensive; my own solution for a fact is wrong. I'll try to explain what I am saying. Say if 3 vertices each have the maximum degree and are connected in a line, and the middle one has many 1 degree neighbours, more than the left and right ones, then we should still remove the left and right vertices

Consider the following test case:

1

22

1 2

3 4

5 6

7 8

9 10

11 12

13 14

15 16

17 2

17 4

17 6

17 8

18 10

18 12

18 14

18 16

17 19

18 19

19 20

19 21

19 22

On this test case, my code gives 8 as the answer, whereas the actual answer is 9. Idk how my code passed all the test cases!

»
15 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

Actually, you can transform Problem F2 into a tree, and solve the problem from the back to the front. In that way, it is all about merging components together, which can reduce the time complexity from $$$\mathcal{O}(n\log n)$$$ to something like $$$\mathcal{O}(n\alpha(n))$$$ (the time complexity of a dsu).

The detail that is worth noticing is that if two subtrees with the same parent are both visited, you should merge them too. You can use a virtual node representing the "parent" to solve this case.

Here is the Python implementation (not optimized fully because I wrote it in about 15 minutes): My Submission.

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In Problem C, this code is according to the solution provided in editorial

Can anyone help understand why this code does not work ?

https://mirror.codeforces.com/contest/2063/submission/302540075 Edit : found it :)

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

second one was really good question.

»
15 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I had a very funny and implementation-heavy solution for problem D. I put x-coordinates of the bottom line in the ordered_set and same for the top line. Then, I did some greedy, I chose min and max point on either bottom or top line (wherever the difference between the coordinates is greater), then I chose a middle point on the opposite side using ordered_set. However, it won't be maximum amount of operations because there can be a case where there will be a lot of points on one side and <2 on another. Therefore, I reverted once last operation and chose points from another side. I don't really know how to prove it, but I got AC by on the first try.

My submission: 302423073

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Hey everyone, My first comment here :)) I am not getting why my solution for C is incorrect. I am just choosing the nodes with maxdegree and second max degree and checking cases where if maxdegrees are more than 1 and are they connected or not etc. pls help:( my submission: 302456927

code
  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Did i post the comment correctly?? idk:\

    • »
      »
      »
      15 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      Definitely not

      You should put the block in a spoiler div, so that you don't flood.

      < spoiler summary="Code">

      ~~~~~ Your code here... ~~~~~

      </spoiler>

      Use the "Preview" button to make sure you get a satisfactory result

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anybody explain me in C question second approach why only trying two vertices of highest degree gave the right answer.

»
15 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Well, F2 can be solved in O( N log MOD ) ( log MOD for calculating inverse mod). I only need to observe the brackets as a tree (assuming that (0, N + 1) is also a good pair)) and then "removing" the brackets (by reversing the queries), which I can maintain by DSU.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

4th problem "Observe that the value dependent on p is a prefix sum of a strictly decreasing sequence, and thus is convex." can someone please explain above sentence form editorial of 4th question. Suppose we take array containing values 1/i where i being index (talking about 1 based indexing) and we take prefix sum then we do not get convex function. Please tell me where I am going wrong. If someone has done 2 pointer method or binary search then please share your solution.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    as the value is summation(An-i-1) — summation(Ai) , as both are strictly increasing subtraction of one will be decreasing and the net graph would be a convex

»
15 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

A simpler solution for 2063D — Game With Triangles without binary search, in O(n+m):
At a step with chosen p,q, the next step will be one of ((p+1,q),(p,q+1),(p+2,q-1),(p-1,q+2)). Greedily choose the best next step and assign new value of p,q

https://mirror.codeforces.com/contest/2063/submission/302430925

»
15 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

It is really terrible. F1<<E<<D.

»
15 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

But obviously there is a offline method can solve F2 in $$$O(n\alpha(n))$$$ with dsu, and u can use this skill to optimize it to $$$O(n)$$$.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yes, we understand that this exists. Anyways, it is very fascinating that the small to large solution can solve it online in $$$\mathcal{O}(n \log n)$$$.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain the following things more clearly in Problem E's editorial?

  1. I didn't understand why the first summation would count the pairs $$$ d_u = d_v $$$ twice? Hence, I also didn't understand its fix.

  2. in the second summation, i didn't understand the logic behind the summation. the above paragraph is very clear which explains the consideration of vertex $$$w$$$ as $$$LCA$$$ but I didn't understand what $$$s_u(S - s_u)$$$ means logically. Hence, the part after it is also unclear.

Explanation would be very appreciated from soneone who knows the answers to these confusions.

Thanks in advance 🧡

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    1. The pairs $$$(u,v)$$$ where $$$d_u \lt d_v$$$ is only counted once when we check $$$u$$$. However when $$$d_u=d_v$$$, $$$d_u \le d_v$$$ and $$$d_v \le d_u$$$ both hold, and thus $$$(u,v)$$$ and $$$(v,u)$$$ is counted separately while it should not have been.
    2. $$$s_u (S-s_u)$$$, combinatorially, means choosing one vertex from subtree of $$$u$$$, and then choosing another descendant which is NOT in the subtree of $$$u$$$ (thus, the number of cases of the latter is $$$(S-s_u)$$$).
    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      If there is some node $$$ v $$$ on the path $$$ w = \gt u $$$, then won't it be counted in $$$ S - s_u $$$? If it will be counted then it violates the conditions of good pairs, no?

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I'm confused about this part with Problem D.

Let us define a function $$$g(p,q)$$$ as the maximum score after performing "Operation A" $$$x$$$ times and "Operation B" $$$y$$$ times, assuming it is possible.

Do you mean $$$p$$$ times and $$$q$$$ times? I'm not sure where $$$x$$$ and $$$y$$$ are suddenly coming from.

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In Problem C, Why it is not optimum to remove the node with maximum number number of edges, then remove the 2nd node with the maximum number of edges after removing the edges from the first operation? like this solution, why it fails? https://mirror.codeforces.com/contest/2063/submission/302950582

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How are people solving problem E with small to large merging?

I want to get more familiar with that concept but I am not able to come up with the solution from that approach

»
15 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Greedy solution for D if anyone finds above difficult to understand.

https://mirror.codeforces.com/contest/2063/submission/303715832

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
ll n;
        cin >> n;
        vector<pii> a(n + 1, {0, 0});
        vector<vector<int>> edge;
        for (int i = 0; i < n - 1; i++)
        {
            int u, v;
            cin >> u >> v;
            edge.push_back({u, v});
            a[u].s1++;
            a[v].s2++;
        }
        int comp = 0;
        ll maxi = -1, idx = -1;
        for (int i = 0; i <= n; i++)
        {
            maxi = max(maxi, a[i].s1 + a[i].s2);
            if (maxi == a[i].s1 + a[i].s2)
            {
                idx = i;
            }
        }
        if ((a[idx].s1 == 0 && a[idx].s2 == 1) || ((a[idx].s1 == 1 && a[idx].s2 == 0)))
        {
            comp += 0;
        }
        else
            comp += (a[idx].s1 + a[idx].s2);
        
        a[idx].s1 = 0, a[idx].s2 = 0;
        for (auto it : edge)
        {
            if (it[0] == idx)
            {
                a[it[1]].s2--;
            }
            else if (it[1] == idx)
            {
                a[it[0]].s1--;
            }
        }
        
        maxi = -1;
        idx = -1;
        for (int i = 0; i <= n; i++)
        {
            maxi = max(maxi, a[i].s1 + a[i].s2);
            if (maxi == a[i].s1 + a[i].s2)
            {
                idx = i;
            }
        }
        if (a[idx].s1 == 0 && a[idx].s2 == 0)
        {
            comp = max(comp - 1, 0);
        }
        else if ((a[idx].s1 == 0 && a[idx].s2 == 1) || ((a[idx].s1 == 1 && a[idx].s2 == 0)))
        {
            comp += 0;
        }
        else
            comp += (a[idx].s1 + a[idx].s2) - 1;
        cout << comp << endl;    

where it is giving wrong answer?

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F2 is actually a very standard offline reverse query + DSU trick, took me an incredibly long time to observe...

»
15 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

can anyone debug my code I just looked the most 3 degree nodes for all possibilities and if there is a edge between the nodes the answer is the sum of degree sum-2 if there is not the answer is degree sum-1 My submission: https://mirror.codeforces.com/contest/2063/submission/304652149

»
15 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

304654404 304653426 304652776

2063C — Remove exactly two

Can someone please explain why any of them gives wrong answer ?

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem C, Solution 2:

Instead of trying 2 max degree nodes, we can choose the node having maximum depth amount all nodes having the max degree count. This is always work as the size of one connected component will be very much larger than other. And it leaves us a choice to choose 2nd node with more degrees.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hii everyone ,trying to solve problem C using DP ,although i have solved it using greedy but just curious.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I'm extremely late, but just in case it's helpful to anyone looking at these problems later, I think the alternative solution to F2 in the editorial is also overkill. A few others in the comments have alluded to the solution I wrote, but I'll walk through it in a bit more detail.

Observe that the good pairs have a natural tree structure. Construct one root vertex and n vertices corresponding to each of the good pairs. The parent of each good pair is the innermost good pair in which it is contained, or the root if it isn't contained in any good pair. Intuitively, this tree structure captures the containment relationships between the good pairs. (It might be easier to conceptualize this by imagining adding an extra pair of parentheses enclosing the entire string and assuming this pair is given as the first good pair. Then we can say this pair is the root, and the root is otherwise no longer a special case.)

Define MBSes as in the editorial, except that the good pair enclosing each MBS is included in the MBS. For example, in the bracket sequence (()??), where the question marks are unrevealed parentheses, the MBSes are (??) and (). The key observation is that each good pair that has not been revealed yet is in the same MBS as its parent. (The intuition is that if the parent pair P of the unrevealed good pair X has been revealed, then since P is the innermost good pair containing X, X must be in the MBS contained by P. Otherwise, if P has been revealed, since P is the innermost good pair containing X, the innermost pair containing P must also be the innermost good pair containing X, so X and P are in the same MBS.) Moreover, these connectivity relationships completely define the MBSes, i.e., any pairs that are not forced to be in the same MBS by this property are not in the same MBS.

This is enough to solve the problem offline in $$$O(n \alpha(n)).$$$ Build a DSU where the good pairs are vertices, and iterate over the good pairs in reverse. When we reach a good pair, merge its vertex in the DSU with the vertex of its parent and update the answer accordingly (i.e., if the old components have sizes $$$C_x$$$ and $$$C_y$$$, multiply by $$$\frac{C_{x+y-1}}{C_{x-1} C_{y-1}}$$$).

Obviously, a solution's elegance is subjective, but I think this is a pretty nice solution (and I like this problem a lot more because of this solution than I would have if the only option was to bash with data structures). It's also pretty concise, with less than 40 lines of non-template code. My VC is ongoing, so I can't read other contestants' code, but my guess is that this was more concise than the solutions of other top contestants, allowing me to solve F faster than most other competitors despite taking the time to type F1 separately.

A few other thoughts on the round:

  • A few people pointed out in the comments that E can be solved using small-to-large merging. I don't think this is that bad; the intended solution is not much more difficult to come up with and is very concise. I'd be surprised if small-to-large actually saved a nontrivial amount of time.
  • I wasn't a big fan of D; I found that working out the details took longer than coming up with the general greedy strategy. I felt the same way about C to a lesser extent (I just didn't feel like there was an exciting/subtle idea there), but it didn't bother me much since the implementation was short and it was thus easy to just move on to the next task.
  • I don't think you needed to apologize for not being more clear that contestants should read every problem; the fact that F1 was worth fewer points than D/E should tip off contestants to the fact that it might be easier.
  • F2 was my favorite problem of the round.

Thanks for the contest!

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem D, when I solved the ternary search using the definition of ml = (l * 2 + r) / 3 and mr = (l + r * 2) / 3, the solution got accepted.

But when I used the general definition of ml = l + (l + r) / 3 and mr = r - (l + r) / 3, I got wrong answer verdict on testcase 7. Can anyone explain why?

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

HELP in C!

My Submission — 366425958 I am not able to understand why my code is failing, when i found out 1158th testcase of Test 2 it is,

8 8 5 7 5 2 6 2 1 2 5 1 4 1 3

and the compiler is saying that your output is 4, but while i am testing locally i am getting output as 5.