Puchi and Luggage
Practice
4 (210 votes)
Algorithms
Approved
Easy
Merge sort
Open
Ready
Sorting
Problem
91% Success 22668 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends, gives him the luggage of a particular weight to carry. You will be given the weight of luggage of each friend in the array Weight, where Weighti is the weight of luggage of ith friend carried by Puchi on ith day. It is given that all the luggages carried by Puchi are distinct in their weights.
As Prateek assigned this job to Puchi, so for each day, he wants to know the number of days in future when Puchi will have to carry the luggage , having weight less than the weight of luggage of current day.
Please help Prateek for the same.

Input:
The first line contains a single integer T, denoting the number of test cases. In each test case, the following input will be present:
First line contains an integer N, where N represents the number of friends.
Next N line contains N integers, where ith line contains ith integer, which represents Weighti.

Output:
Output exactly T lines. Each line contains N integer separated by a space, where ith integer represents the number of luggage of future, which are less than the weight of luggage of the current day.

Constraints:

Subtask 1:
1 <= T <= 30
1<= N <= 104
1<= Weighti <= 106
Subtask 2:
1 <= T <= 10
1<= N <= 105
1<= Weighti <= 106

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
22 votes
Tags:
ApprovedEasyMathOpenSorting
Points:20
3 votes
Tags:
ImplementationSortingAlgorithms,2D dynamic programming
Points:20
23 votes
Tags:
AlgorithmsEasyHiringMerge sortSorting