Ones
Time limit2.5sMemory limit1024 MB
Find where the longest run of 1s sits in a hidden bit array, using as few flip-and-query rounds as possible, where each query returns only the new longest run length.
- Level
Medium6 of 10
- Topics
- Array, Binary search, Divide and conquer
- Solved
- No attempts yet
Problem
There is a hidden array of bits . In one query, you can choose a subset of positions in the sequence and flip the bits at those positions. Flipping a bit changes it to a , and flipping a bit turns it into a . After each query, you are given the length of the longest consecutive subarray of s in the new array. A flipped bit stays flipped until a later query flips it back.
You want to find where the longest subarray of ones is located after all queries (or any one of them, if several exist). Write a program that does this in as few queries as possible.