This problem can be solved in a few ways:

  1. For easy sub-task, a simple for loop checking the query limit would suffice.

  2. Concept of bucket sort can be used to store the indices of occurrences of each number in separate vectors and perform a binary search on sorted array when a query with the specific number comes.

  3. The given array can be discomposed into square root N number of segments where N is the size of the array and then keep a map for each of the discomposed chunks.

  4. Queries can be taken at once and the answers can be generated offline. Please refer to “SPOJ Dquery” for a similar test.

  5. It can solved using Merge Sort Tree, although the time advantage may not be required for this case.

Statistics

61% Solution Ratio
Mr.HmianEarliest, Aug '21
nusuBotFastest, 0.2s
nusuBotLightest, 6.9 MB
ITisMAHMUDShortest, 450B
Toph uses cookies. By continuing you agree to our Cookie Policy.