Array Manipulation at Moloco (Hard)
InterviewTime limit2sMemory limit512 MB
For each position i in a permutation-like array, count how many earlier elements are smaller than A[i], with n up to one million.
- Level
Medium6 of 10
- Topics
- Segment tree, Binary search, Sorting, Array
- Solved
- No attempts yet
Problem
Managing and analyzing big data is an important part of Moloco's core business. One day a colleague brought in a tricky issue, and now you have to resolve it.
You are given an array of distinct integers that describes the raw data. From it you must build a new array of integers, where is the number of elements that sit before position and are smaller than .
For instance, if , then .
Input
The first line contains an integer . ()
Each of the following lines contains one element of the array. Line holds . All elements are distinct, and .
Output
Print lines. Line contains the single integer .