How to count how many elements are greater than X on your left

Revision en1, by Rhangel, 2017-07-18 17:44:51

Hello guys,

The problem consists of a vector with size N (0 < N <1e6), a position i is chosen to determine how many elements are greater than the element v [i] in the interval [1, i -1]. In the problem there will be 1e6 queries. I would like to know how to solve this kind of problem with complexity close to O (log n) per query.

Sample:

1 7 4 5 6 7 8

Choosing the element in the 5th position (value 6) in the range [1, 5 — 1] there are 2 elements greater than 6.

Tks. :D

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Rhangel 2017-07-18 17:44:51 556 Initial revision (published)