i_love_sqrt_decomp's blog

By i_love_sqrt_decomp, history, 8 months ago, In English

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.

  • Vote: I like it
  • +16
  • Vote: I do not like it

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

Solve with segment tree.

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

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

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 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

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

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

bro really loves sqrt decomposition

»
8 months ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

Problem name??