Subarray problem: Given integer array A (only positive numbers), is there a continuous subarray of any length with sum S? Sliding window solution to this is O(N).
Now if we have many such queries S on static array, we can do preprocessing. We can compute all subarray sums in O(N^2) and store them in a hash table. This also takes up O(N^2) space. Then we can process the queries in O(1) just looking up S from the hashtable
My question is, is there some O(N log N) prepeprocessing? Even if that means droping the queries to O(log N).