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

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

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
  • Проголосовать: нравится
  • +82
  • Проголосовать: не нравится

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

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

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

    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.

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

      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?

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

        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.

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

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

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

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

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

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

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

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/

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

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

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

BFS is enough for Water Container Moves