cry's blog

By cry, 9 months ago, In English

Hello Codeforces.

I was stuck on a 3 hour flight with nothing to do, so what better way to spend my time than catching up on the new CSES problems. But it turns out I finished those too quick so I guess I'm writing the solutions for some of them here. No one probably asked.

This will only cover the new problems from the 2025 update and in the Additional Problems I section. For old problem solutions you can probably find them somewhere on the internet. For new problems not in this section, some of their solutions are in this blog.

Distinct Values Sum

Smash Me

Distinct Values Splits

Smash Me

Beautiful Permutation II

Smash Me

Bubble Sort Rounds I

Smash Me

Bubble Sort Rounds II

Smash Me

Nearest Campsites II

Smash Me

Counting LCM Arrays

Smash Me

Square Subsets

Smash Me

Subarray Sum Constraints

Smash Me

Water Container Moves

Smash Me

Water Container Queries

Smash Me

Maximum Average Subarrays

Smash Me

Subsets With Fixed Average

Smash Me

Two Array Average

Smash Me

Permutation Subsequence

Smash Me
  • Vote: I like it
  • +82
  • Vote: I do not like it

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

What's $$$\mathcal{O}(\text{fast enough})$$$ on Counting LCM Arrays ?

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

    around $$$\mathcal{O}(\sqrt{k} + \log n \frac{\log k}{\log \log k})$$$ per testcase. Simple trial factorization uses $$$\mathcal{O}(\sqrt k)$$$ time to factorize $$$k$$$, and $$$\mathcal{O}(\log n \frac{\log k}{\log \log k})$$$ is to do matrix exponentiation $$$\omega(k)$$$ times (see the prime omega function) where each exponentiation sequence takes $$$\mathcal{O}(\log n)$$$ time.

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

      Would you mind explaining this bound?

      Since we have to factor the number, I was thinking it would be O(T*log(n)*C) where C is the number of primes <= sqrt(1e9) (or at least T*log(n)*log(k)). Is there a faster way to factor k?

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

        This is true, I forgot about the factoring part. Other than that, I had approximated the amount of distinct prime factors as $$$\mathcal{O}(\log \log k)$$$, but it turned out to be $$$\mathcal{O}(\frac{\log k}{\log \log k})$$$. I will now edit my initial reply accordingly.

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

In Water Containers Queries, how do you prove that mod GCD condition is sufficient?

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

This is against the spirit of CSES. You're supposed to solve the problems yourself and try later if you can't.

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

I tried looking for CSES Bitwise Operations Tutorial but could not find one. Is there one available ? If there is one, please can someone provide me the link to that tutorial.

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

For Maximum Average Subarrays, shouldn't $$$pt_j$$$ be the previous point on the lower hull of the points?

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

can Square subset be solved using XORs? I am represenenting ech number by its prime factors like a^b^c... but this gives wrong, can someone help me?

code: https://cses.fi/paste/bc4ea671691d162bf06613/

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

Link for the code for first problem Distinct Values Sum isn't working cry can you please fix it ? btw i like the idea for problem <3

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

BFS is enough for Water Container Moves