Блог пользователя LMydd0225

Автор LMydd0225, 12 месяцев назад, По-английски

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
Разбор задач Codeforces Round 1052 (Div. 2)
  • Проголосовать: нравится
  • +201
  • Проголосовать: не нравится

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +39 Проголосовать: не нравится

We should appreciate fast editorials :))

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

Thanks for the fast editorial! (Maybe the fastest)

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Thanks for fast editorial

»
12 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +10 Проголосовать: не нравится

FAST EDITORIAL!! Thanks for the contest :)

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

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 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

insanely fast editorial ty

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

How to solve D with trie?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

WOW faster than nasa's internet speed!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Not able to submit code in first ~15 minutes.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can D be solved with bit Trie?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

respect++ for fast editorial

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Can someone explain problem E more clearly?

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +4 Проголосовать: не нравится

    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 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +25 Проголосовать: не нравится

Solution link using Trie Bit for D1 & D2

Idea
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

nice contest, speedforces

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

i can not sleep tonight

»
12 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

How is checker for problem C made?

Edit:Understood

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

the fastest round I have ever witnessed!!!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится
  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +13 Проголосовать: не нравится

    Why using heap. I did with trie only. 339778312

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +4 Проголосовать: не нравится

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

      • »
        »
        »
        »
        12 месяцев назад, скрыть # ^ |
        ← Rev. 2  
        Проголосовать: нравится +4 Проголосовать: не нравится

        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 месяцев назад, скрыть # ^ |
          ← Rev. 3  
          Проголосовать: нравится +1 Проголосовать: не нравится

          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 месяцев назад, скрыть # ^ |
             
            Проголосовать: нравится +6 Проголосовать: не нравится

            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 месяцев назад, скрыть # ^ |
            ← Rev. 2  
            Проголосовать: нравится +3 Проголосовать: не нравится

            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 месяцев назад, скрыть # ^ |
               
              Проголосовать: нравится +1 Проголосовать: не нравится

              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 месяцев назад, скрыть # ^ |
                ← Rev. 3  
                Проголосовать: нравится +5 Проголосовать: не нравится

                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 месяцев назад, скрыть # ^ |
                   
                  Проголосовать: нравится +3 Проголосовать: не нравится

                  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 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          I used high to low trie and it still passed.

          343100466

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Oh WHOA, that was fast.

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

Great problems!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I love problem C

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Cool round, thx!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +4 Проголосовать: не нравится

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 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Now I also love problem E

»
9 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain how to solve D1? Using trees