It's very interesting problem and I think it can be solved using Segment Tree.
Here are my idea (I hope it works fast enough):
For each segment, we need to store 4 info:
- leftmost index of number < 1
- rightmost index of number < 1
- max size for this segment (store as range a and b)
- lazy flag (true/false)
When we want to query max size, we can do recursive call to calculate the final answer.
Assume our method was calcAnswer(left,right).
resA = calcAnswer(left, mid);
resB = calcAnswer(mid+1,right);
Max size will be max(resA.max_size, resB.max_size, combine(resA.right_index,resB.left_index)).
If the number of elements in array A[] are small (N<=50000), we can use Mo's Algorithm.