Your solution is O(nq) which will most definitely TLE. The runtime error is because A_i<10^8 where as you have only precomputed for A_i<131072.
To solve it in O(n+q) refer to
1 Like
Your solution is O(nq) which will most definitely TLE. The runtime error is because A_i<10^8 where as you have only precomputed for A_i<131072.
To solve it in O(n+q) refer to