We show how, given a straight-line program with g rules for a binary string B of length n, in O(g2/3n4/3) time we can build a linear-space index such that, given m and c, in O(1) time we can determine whether there is a substring of B with length m containing exactly c copies of 1. If we use O(nlogn) space for the index, then we can list all such substrings using O(m) time per substring.
@article{arxiv.1210.8386,
title = {Grammar-Based Construction of Indexes for Binary Jumbled Pattern Matching},
author = {Travis Gagie},
journal= {arXiv preprint arXiv:1210.8386},
year = {2012}
}