Implement fast range query using prefix sum