wakanda-forever's blog

By wakanda-forever, 4 weeks ago, In English

Thanks for participating. We hope you liked the problems and enjoyed the round.

2226A - Disturbing Distribution

Idea: wakanda-forever
Preparation: wakanda-forever
Solution: wakanda-forever

Solution
Implementation
Rate The Problem!

2226B - Everything Everywhere

Idea: wakanda-forever
Preparation: wakanda-forever
Solution: wakanda-forever

Solution
Implementation
Rate The Problem!

2226C - Mental Monumental (Easy Version)

Idea: wakanda-forever
Preparation: wakanda-forever
Solution: wakanda-forever

Solution
Implementation
Rate The Problem!

2226D - Reserved Reversals

Idea: wakanda-forever
Preparation: wakanda-forever
Solution: wakanda-forever

Solution
Implementation
Rate The Problem!

2226E - Mental Monumental (Hard Version)

Huge thanks to chromate00 for suggesting this task.
Preparation: wakanda-forever
Solution: Proof_by_QED

Solution
Implementation
Rate The Problem!

2226F - Inversion Invasion

Idea: wuhudsm
Preparation: wuhudsm, wakanda-forever
Solution: wakanda-forever

Solution
Implementation
Rate The Problem!

2226G - Stop Spot

Idea: wuhudsm
Preparation: wuhudsm, wakanda-forever
Solution: wuhudsm

Solution
Implementation
Rate The Problem!
  • Vote: I like it
  • +86
  • Vote: I do not like it

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

first. $$$B$$$ is a great segtree problem

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

    You mean $$$E$$$?

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

      No, for $$$B$$$ you can notice that if you fix an index $$$i$$$ in the array, then for any $$$j \ge i$$$ the value of $$$[\max(arr[i..j]) - \min(arr[i..j])] - \gcd(arr[i..j])$$$ is monotonic (it only increases as $$$j$$$ increases). That's because, whenever you add an element, the $$$\gcd$$$ can only decrease and the $$$\max - \min$$$ can only increase.

      So since the property is monotonic, you can maintain two sliding windows $$$i..j$$$ and $$$i..k$$$ where $$$i..j$$$ represents the range of endpoints $$$i \le e_1 \le j$$$ to $$$i$$$ such that $$$[\max(arr[i..e_1]) - \min(arr[i..e_1])] - \gcd(arr[i..e_1]) \le 0$$$ and $$$i..k$$$ represents the range of endpoints $$$i \le e_2 \le k$$$ such that $$$[\max(arr[i..e_2]) - \min(arr[i..e_2])] - \gcd(arr[i..e_2]) \lt 0$$$. And the answer for an $$$i$$$ is just $$$j - k$$$.

      To easily query the $$$\max, \min, \gcd$$$ of a subarray, you can use a segment tree or a sparse table.

»
3 weeks ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

Cannot be on the same page as the author in 2226D - Reserved Reversals

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Was doing exactly the same stuff for C, but wasn't convinced with any greedy approach that came to mind.

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

    i managed to find the mods for each one but i couldnt think of binary search ffs -elo

»
3 weeks ago, hide # |
 
Vote: I like it +32 Vote: I do not like it

D's so hard :(

»
3 weeks ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

that C was great, I tunnel visioned on the wrong greedy

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

I am doing the exact same thing for C as in the editorial 372865973. Where am I going wrong?

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

    Same question! I'm using binary search as well, I don't know what I'm missing here. 372869255 :/

    • »
      »
      »
      3 weeks ago, hide # ^ |
      Rev. 4  
      Vote: I like it 0 Vote: I do not like it

      Waitt...... I didn't know my_map[key] creates an element if the key doesn't exit....... I can't believe I spent an hour on this problem and this was the issue (372875201). Ughhhh!!!! Goodbye Specialist ;(

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

problem C is awesome

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

E reminded me of https://cses.fi/problemset/task/2425, was close to solving it :(

»
3 weeks ago, hide # |
 
Vote: I like it +26 Vote: I do not like it

Fun fact: F can be done in $$$O(\sqrt n)$$$

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

For Problem E, I started thinking about going from smallest prefix to the longest but concluded it was not feasible under the time limit. Then it hit me to go from largest prefix to smallest. pretty amazing problem imo.

»
3 weeks ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Screencast with commentary : Could only solve A and B. Had the correct idea for C, but had some bugs in implementation.

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

I imagine that some people tried an increasing greedy instead of a decreasing greedy for C. This does work but the solution is less clean. The idea is still to binary search on a valid $$$m$$$. We check if the first $$$m-1$$$ elements can be filled. For a given $$$m$$$, we can do the following:

Create a $$$cnt$$$ array, and maintain an unresolved left bound $$$L$$$ and right bound to pick elements $$$R$$$. Iterate $$$L$$$ from $$$0$$$ to $$$m-1$$$. If $$$cnt[L] \geq 1$$$, then the element already contributes to the mex. Otherwise, we need to find a location $$$R$$$ to take the next element from. Increment $$$R$$$ until:

  1. $$$R \geq 2L + 1$$$ (mod condition)
  2. If $$$R \leq m-1$$$, we need at least one element in the current location: $$$cnt[R] \gt 1$$$.
  3. If $$$R \gt m$$$, we can use any nonzero element.

Such a two pointer approach works in $$$O(n\text{ log }n)$$$.

Submission: 372875264

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

A's statement was weird, like B is 10 times clearer, and the difference between C and D in difficulty is massive

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

    A is so so much harder than B, especially in understanding what the problem is trying to say. I am too noob to comment about C but it was a spike too for sure.

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

I've spent 2 hours on C, but for some strange reason the output in the cf tester differed with the output in my IDE. Like sometimes the tester would give me WA on the first test, although I would get the correct output in my IDE. In an online compiler I also get the correct answer. What can be the reason for that? I also asked it during the contest, but did not get an answer

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

    It may be that the variable has not been initialized.

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

    If you declare an array of size 100 (int arr[100];) but your loop accidentally accesses arr[100] (the 101st element), you invoke Undefined Behavior.

    Locally: The memory right next to your array might be empty or belong to a harmless variable, so the program silently continues and prints the right answer.

    Codeforces: That out-of-bounds read/write might overwrite a critical variable, cause a silent memory fault, or read garbage data, entirely changing your output.

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

sorry if it was newbie question, but i gotta ask.

why do we in problem one(2226A) make the answer expecting at least a single 1 in the array? isnt it possible that the array doesnt have any ones? sorry again for the newbie question, and thanks.

»
3 weeks ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

One of the best C problems in the recent contests !

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

Binary search on C was so good

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

Highly recommend to check out 2093E - Min Max MEX if you liked C. It introduces another idea to MEX that this editorial didn't use. Anyways cool round!

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
Faster solution for C
»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Solution to D is too feeble, such questions should be avoided in contests

  • »
    »
    3 weeks ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    yeah!! gave full 50 mins to that D, still wasn't able to figure it in the contest, should have tried E :(

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

I got killed by C again today !!!

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

I only solved A and B ...

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Problem C was really good problem, I'm so like it! Thanks for amazing contest!

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

Can anyone pls tell me why my code is failing for C i tried a different version where store all numbers that are between 0 to n-1 in array in set and store all duplicate or values greater than equal to n in a list then sort the list then try to make the mex by iterating over 0 to n-1, if set contains i then go to next if not then iterate the list and check if it can be used to make i and so on and if cant find any value then return the i otherwise keep on iterating i till n-1 and return n which is the maximum mex, here's my code -->https://mirror.codeforces.com/contest/2226/submission/372918788

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

    Take example 0 0 0 3. Size n = 4. You put 3 in your set (because 3<= n-1) making it unusable and then your code outputs 1 as answer whereas the correct answer is 2.

    Logic flaw : Say the correct answer is m(<= n). When you put numbers upto n-1 in your set, you let go of numbers from m to n-1 which could have been utilized to get to the correct answer (which is m here).

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

D is so hard.

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

Problem E looks like a simple extension if C was solved, the only tricky part here is converting the concept of lazy segment tree into an implementation. I have tried different variations of implementation this whole morning, but still couldn't figure it out. Maybe I have to work on lazy segment trees :(

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

    Got to see the solution for problem F, the trick was too clever, and it lifted a ton of thinking for inversions calculation for each independent permutation. I loved it. Great work...

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

too hard

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

In Problem $$${C}$$$, it should be $$$\lceil \frac{x}{2} \rceil$$$ rather than $$$\frac{x}{2}$$$.

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

C cooked me so hard, but still, i have to say it was a great problem!

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

if we try 2226C — Mental Monumental (Easy Version), without binary search and two pointer in this way then what problem is occurring. can anyone help me.

test_cases=int(input())
 
for _ in range(test_cases):
    n=int(input())
    l=list(map(int, input().split()))
    l.sort()

    if n==1:
        print(1)
        continue
    elif n==2:
        a=False
        for i in l:
            if i==1 or i>2:
                a=True
                break

        if a==True:
            print(2)
        else:
            print(1)
        continue

    value_ok=0
    print_avb=None
    forward=None

    valid=[True]*n

    for m in range(n):
        if l[m]==1 or l[m]>2:
            value_ok=1
            forward=True
            valid[m]=False
            break

    if forward==True:
        for i in range(2,n):
            for k in range(n):
                if l[k]==i and valid[k]==True:
                    valid[k]=False
                    value_ok=i
                    print_avb=False
                    break

            if print_avb!=False:
                for j in range(n):
                    if (l[j]>2*i) and valid[j]==True:
                        valid[j]=False
                        value_ok=i
                        print_avb=False
                        break

            if print_avb!=False:    
                break
            else:
                print_avb=True

    print(value_ok+1)

what is the problem here??

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

HELLO

»
2 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

this editorial is so good!

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

for the problem A , for the test case 3 2 1 the minnimum cost given is 6,but if we choose 3 first then proceed to choose 2 & 1 together the cost cost would be 5,(3+(2x1)) then why cant we do that as we can choose element singly or in subsequence please replyy

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

    you cannot choose a decreasing sub sequence. 2 > 1 so you cannot take [2, 1]

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

      what would answer to the test case [1 2 3] would be?

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

        It would be $$$5$$$.

        Spoiler