Problems > Smaller Ones Before Me

Smaller Ones Before Me

Difficulty: 1700 3500 ms 128 MB

fenwick sorting

For each position, print how many EARLIER elements are strictly smaller than it.

Input: the first line has N; the second line has N integers.

Output: N integers: the count of smaller predecessors per position.

Constraints:

  • 1 ≤ N ≤ 105
  • |ai| ≤ 109

Sample Tests

Input 1
5
3 1 4 1 5
Output 1
0 0 2 0 4
Input 2
2
2 2
Output 2
0 0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.