1,102 views
2 votes
2 votes

Reply with solution @Arjun sir,@habibkhan,@vijaycs

1 Answer

Best answer
6 votes
6 votes

One possible way.

  1. Construct a count array such that count[m] =  No of elements with value m // O(n)
  2. Convert count to a cumulative count array such that count[m] = No of elements upto and including m // O(k)
  3. Range Query[a,b] = count[b] - count[a-1]  //assuming $b >= a$
  4. Total preprocessing Time = O(n+k)

code 

selected by

Related questions

1 votes
1 votes
2 answers
3
manvi_agarwal asked Sep 3, 2018
672 views
https://gateoverflow.in/?qa=blob&qa_blobid=11583750777176064728Approach please
0 votes
0 votes
0 answers
4
iarnav asked Jan 12, 2018
572 views
in questions like how many multiplications of n are needed are being solved by dividing n into n/2 * n/2 and then end up with recurrence t(n) = t(n/2) + O(1) How to reach...