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

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

The problem that I'm doing: 1548B - Integers Have Friends

My submission: 167895313

Basically what I'm doing is finding the maximum length of the subarray in the "diff" array, where their GCD is greater than or equal to 2. I made a GCD segment tree and consider for every index i, I will binary search the greatest j where gcd(diff[i..j]) >= 2. The time complexity of this algorithm should be O(n log^2 n), but I got TLE (5 times with the same code). Is there anything that I'm missing? Thanks in advance.

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

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

The actually time complexity for gcd(a, b) is O(log(min(a, b)), so the time complexity of your solution should be O(n log n log 1e18)

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

Time complexity of your solution is $$$\mathcal{O}(n \log^2 n \log MAX)$$$ because of gcd. It gets accepted with C++ 20 and pragmas though.

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

Replacing segment tree with RMQ gets AC pretty comfortably. Here's my solution 167921793

»
9 месяцев назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

(edited)