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

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

I have a problem that reduces to doing 2 kinds of queries:

  • Add a number in $$${1,-1}$$$ to a range.
  • Query the number of 0s in a suffix. It's guranteed that the array is nonnegative.

Constraints: $$$n\leq 10^5, Q\leq 192\cdot10^5$$$. My best solution did this problem in about 3.5 seconds using sqrt decomposition.

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

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

Solve with segment tree.

You need to maintain the minimum and the number of the minimnum in every vertex's subtree.

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

hi yoshi!!

i think youre trying to solve prob 2 from the recent trai he hung vuong

heres my solution: construct a lazy segment tree that for each node that represents the range (l -> r), the node will store the minimum element and its frequency in the range.

if the current minimum element in a range is 0, then we already have the corresponding answer. else there would be no zeros because the minimum element is > 0.

this way we could query/update in o(logn).

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

The input is incredibly large and I doubt if your constraint on $$$Q$$$ is wrong.

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

bro really loves sqrt decomposition

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

Problem name??