Adaptive Range Counting and Other Frequency-Based Range Query Problems