LMydd0225's blog

By LMydd0225, 12 months ago, In English

2146A - Equal Occurrences

Hint 1
Hint 2
Tutorial
Implementation

2146B - Merging the Sets

Hint 1
Hint 2
Tutorial
Implementation

2146C - Wrong Binary Search

Hint 1
Hint 2
Tutorial
Implementation

2146D1 - Max Sum OR (Easy Version)

Hint 1
Hint 2
Hint 3
Tutorial
Implementation

2146D2 - Max Sum OR (Hard Version)

Hint 1
Hint 2
Hint 3
Tutorial
Implementation
Another solution using greedy on trie
Implementation

2146E - Yet Another MEX Problem

Hint 1
Hint 2
Hint 3
Tutorial
Implementation
Bonus

2146F - Bubble Sort

Hint 1
Hint 2
Hint 3
Tutorial
Implementation
  • Vote: I like it
  • +201
  • Vote: I do not like it

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

We should appreciate fast editorials :))

»
12 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Thanks for the fast editorial! (Maybe the fastest)

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

Thanks for fast editorial

»
12 months ago, hide # |
← Rev. 2  
Vote: I like it +10 Vote: I do not like it

FAST EDITORIAL!! Thanks for the contest :)

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

Appreciations for the fast editorial!

P.S: E was so good ( submitting it just 3 seconds before made the adrenaline rush worth it :D) Loved the contest!

»
12 months ago, hide # |
← Rev. 2  
Vote: I like it +1 Vote: I do not like it

insanely fast editorial ty

couldn't do B because I wasn't convinced iterating over sets individually was fastest D:

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

How to solve D with trie?

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

WOW faster than nasa's internet speed!

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

Not able to submit code in first ~15 minutes.

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

    During this period of time, the judge system is still testing the solutions and using all (?) of their resources for it. Once all of the solutions have been rejudged, you will be able to submit again...

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

      I meant I cannot submit code during the first 15 minutes of the contest. The submission page is totally frozen and I cannot paste my code.

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

        really?? Wow, that's pretty strange. I guess for future cases like this you could use the mirror site/submit as file...

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

In C's editorial it is mentioned that we can reverse [l,r] but it length is odd won't it be incorrect because for middle elements p[x]=x and it will be stable then

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

    for every s[i] = '0' either there should be smaller element to its right or larger element to its left , if one of the condition hold true then it is fine , when p[x] =x in the case you mention then there are still elements to its right which are smaller then x , this is the reason why it works.

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

Can D be solved with bit Trie?

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

    Yes, i used trie for D1, but couldn't solve D2 :(

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

    I solved both with trie,I thought that's what everyone else would also have done but to my suprise I didn't found any another submission using trie in my friendlist. I used simple binary trie logic which we generally used to find max xor of an array with any element x,but instead of moving from msb to lsb Moved from lsb to msb so that Gap is not wasted,by Gap mean like in 100 and 001 if we take these two then or will be 101 hence there is 0 between ones which is Gap in my logic.

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

respect++ for fast editorial

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

Can someone explain problem E more clearly?

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

    Let ans[x] = answer if MEX = x.
    Move from left to right. At i'th step we have ans[] array calculated for all elements to the left of i. Now need to update array ans[] for current i:
    ans[a[i]] = 0 because since a[i] mandatory exists (in every subarray (l, i) ), MEX can not be = a[i];
    ans[x] for x < a[i] gets increased by 1 because if MEX x < a[i], then appending a[i] does not change MEX, but adds 1 to answer;
    ans[x] for x > a[i] remains the same, because appending a[i] does not change MEX, but doesn't change the answer.

    To implement it in O(N * logN) a powerful data structure is needed. I've used segment tree with lazy propagation, but may be there are other options.

»
12 months ago, hide # |
← Rev. 2  
Vote: I like it +25 Vote: I do not like it

Solution link using Trie Bit for D1 & D2

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

    How does it work? I tried to greedily search from $$$30$$$ to $$$0$$$ but failed. Could you explain why from low to high works?

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

      I'm not sure either, i also tried from 30 to 0 at first, but it didnt pass the samples so i just reversed it and it ACed (literally prove by AC)

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

        I have the same. Tried D1 from the greatest bit and failed on D2. But after i tried from the least bit and it works! Idk know why, lol.

        • »
          »
          »
          »
          »
          12 months ago, hide # ^ |
          ← Rev. 3  
          Vote: I like it +10 Vote: I do not like it

          The reason is that when we traverse from high to low, if a desired bit is not present, we switch paths to take an available number. However, this may lead us to a number with fewer bits. On the other hand, when traversing from low to high, the correct number is retrieved.

          P.S. — Example

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

            Can you explain why traversing from 0 to 30 find a number with more set bits compare to 30 to 0 because in both approach we are changing path as when we required it.

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

Didn't you wanted to say, in tutorial of problem E, that we want to increase b_i by 1 for all i < a_r ?

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

nice contest, speedforces

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

oh just compare my time limit submission with my accepted submission on D2

i can not sleep tonight

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

How is checker for problem C made?

Edit:Understood

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

for problem tags on C, there are 8 binary search tags . Is that going to be fixed ?

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

the fastest round I have ever witnessed!!!

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

    Why using heap. I did with trie only. 339778312

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

      Hi. Can you explain why it is optimal to solve it from the lowest bit to the highest bit?

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

        Here is a case where high to low bit will fail.

        l = 3, r = 6

        high to low trie -> 26

        low to high trie -> 28

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

          Thanks for your hack, but I just can't understand why it is optimal from low bit to high bit. Could you make a explanation?

          If insert numbers into trie from high bit to low bit, and get the answer from $$$l$$$ to $$$r$$$, it will get WA on $$$[3, 6]$$$ where the correct answer is $$$28$$$, but $$$26$$$ is given.

          If insert numbers into trie from high bit to low bit, and get the answer from $$$r$$$ to $$$l$$$, it will get WA on $$$[1, 4]$$$ where the correct answer is $$$20$$$, but $$$18$$$ is given.

          I solved D1 with the method of traversing from high bit to low bit and get the answer from $$$r$$$ to $$$l$$$ but failed on D2. It's really confusing.

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

            OR is monotone but not lexicographic — adding a 1 in any bit helps, but there's no strict ordering where higher-bit wins over all lower bits combined. MSB-first greedily optimizes the current bit or breaks ties locally; but maximizing total number of 1 bits (or numeric value of OR) can require sacrificing an MSB tie to gain many 1s in lower bits. That requires deferring decisions about higher bits until you’ve examined lower bits → exactly what LSB-first does.

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

            Also in D1, all numbers $$$[0,r]$$$ are present. Therefore, all numbers' XOR are present, but in D2 as the exact XOR can be absent, can lead to picking up wrong number.

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

              But hey can you prove that going from LSB to MSB is always optimal, you showed a case where MSB to LSB fails. But can you prove there exists no case where LSB to MSB fails.

              suppose there exist a case where sacrificing a higher a bit is not optimal but we won't know about it because we already made the decision before reaching highest bit

              • »
                »
                »
                »
                »
                »
                »
                »
                12 months ago, hide # ^ |
                ← Rev. 3  
                Vote: I like it +5 Vote: I do not like it

                Sorry to disappoint you mate, I don't have a concrete proof for this. I did this question purely based on my intuitions which I wrote above, I solved D1 using different approach not trie-based.

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

                  Seems that,to some degree,there exists some equivalence. Consider the solution in the editorial,assuming that the current interval is [l,r] with the t defined in the solution. Without loss of generality,let length of [l,t)<[t,r].With the way in the solution,we pair each x of [l,t) with 2t-1-x. For certain x,if x+t<=r,assuming it finally match with y,then we can swap the matches.To be specific,in the solution it matches like (x,2t-1-x) and (x+t,y),however the result of (x,y) and (x+t,2t-1-x) is the same,because it holds that y&t=t.That's the stage of t,and for later stages with t'<t,it is obvious that the swap holds. To be vivid,assuming we have a values with t and b values without t,we only have to assure we get min(a,b)*t,but how we get it doesn't count. Thus,your solution is clearly right.On the other hand,if we start from the highest bit,for [l,r],if it could be described as [l,t),[t,2t-l-1],[2t-l,r] where r<t+l,then if we greedily try r,r-1,...,we get a wrong solution(where [2t-l,r] match with certian value in [l,t),get the t,however lose t'<t,and the swap mentioned above is no longer equivalent)

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

          I used high to low trie and it still passed.

          343100466

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

      Most of the people had same thought process. I recently solved a problem with BitTrie + remove() method. So, I tried with this and I think this is easier.

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

      Can you please explain your code?

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

Oh WHOA, that was fast.

I mean I checked in after 2-3 hours and it's already here, damn!

Great problems!

»
12 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

I love problem C

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

As for the trie solution to problem D, can anyone explain why it is optimal to solve it greedily from the lowest bit to the highest bit?

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

Cool round, thx!

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

In the Editorial of problem C, in second point shouldn't l become m+1 instead of r = m-1

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

In the Editorial of D2,I find that the example of [11,16] is not the biggest one. It's less than [12,11,16,15,14,13].A small mistake.

»
12 months ago, hide # |
← Rev. 3  
Vote: I like it +4 Vote: I do not like it

There is one more way to prove the solution for Problem D1 using induction and the following two observations:

1 → If we make a partition between a number x = (power of 2) and x - 1, then with respect to this partition, the pairs (x - 1 , x), (x - 2, x + 1), … will be complements of each other. For example: (7, 8), (6, 9), (5, 10) ............. wrt. to partition between (7, 8).

2 → If we take numbers 0, 1, 2, 3, 4, 5, …, r and let x = (maximum power of two such that x ≤ r), then the (count of numbers from x to r) will always be ≤ (count of numbers less than x). More Formally (r - x + 1) <= (x + 1). In short, there are always x + 1 elements from 0 to x — 1 in left, while on the right side (including x) there can be at most x elements. Otherwise, x would become the next power of two, which contradicts our assumption.

For example, if r = 15:

(Maximum power of 2) ≤ r ⇒ x = 8

Count of numbers from x to r = 15 - 8 + 1 = 8

Count of numbers from 0 to x — 1 = 8

Now, just make a partition between x = (max power of 2 ≤ r) and x — 1, do the pairing as in point 1. From point 2, the elements on the right side of the partition will always end first. So, after the first iteration of pairing, we again get a new unmatched array → (0, 1, 2, 3 ....... x).

Now You have the similar subproblem will lesser value of r.

for example if r = 10

first partition -> 7 | 8
pairs (7, 8), (6, 9), (5, 10)

remaninig array -> (0, 1, 2, 3, 4)
second partition -> 3 | 4
pairs (3, 4)


remaninig array -> (0, 1, 2)
third partition -> 1 | 2
pairs (1, 2)
»
12 months ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

Problem E is nice . I tried — like extending ans[i] to ans[i+1] from left to right , right to left . consider all mexs . iterating from left to right . form segments of the bigger number increasing the answer ; nothing properly clicked like the stuff being done in editorial . Thanks .

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

Now I also love problem E

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

Wrong binary search gave so many chills. Learnt a lot thank you!

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

Can someone explain how to solve D1? Using trees

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

    trie ig

    (not my solution I read that in the comments section) so if you really want to know how they solved it you'd have to read the comments