Is it possible to solve this problem with a bitset?

Revision en1, by Medo., 2017-10-12 22:50:35

Hello!

I was recently solving this problem : http://poj.org/problem?id=1823

The problem basically says given an array of maximum size of 16000 where each element is one or zero, we need to perform the following operations.

Set range [L,R] to ones or zeros. Query maximum length of a subarray of ones

The problem can be indeed be solved by a segment tree, however I later noticed that since N is just 16000, we would only have blocks of size 500 ( 16000/32 = 500 ). Now the set, and reset updates part can be done in O(block).

What is remaining is how to query the number of ones, are there any possible bit operations to perhaps do? I only have O(N) solutions..

Please note, I already know the segment tree solution, I'm interested in bitset.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Medo. 2017-10-13 00:10:38 2 Tiny change: 's, are the any ways' -> 's, are there any ways'
en2 English Medo. 2017-10-13 00:05:41 319 (published)
en1 English Medo. 2017-10-12 22:50:35 813 Initial revision (saved to drafts)