Algorithms Final Exam
InterviewTime limit1sMemory limit256 MB
Given the final order listed by midterm rank, print for each student how many midterm superiors they passed minus how many inferiors passed them.
- Level
Medium4 of 10
- Topics
- Segment tree, Prefix sum
- Solved
- No attempts yet
Problem
Sangdeok's final exam is almost here. The algorithms section he takes has students. Algorithms is graded on a curve, so no two students share a rank, and each student's satisfaction depends on the midterm rank and the final rank. Rank 1 is the highest rank. For the student who placed -th on the midterm, the satisfaction is defined as follows.
- is the number of students who placed higher on the midterm and lower on the final than that student.
- is the number of students who placed lower on the midterm and higher on the final than that student.
Number the students by midterm rank. The student who placed -th on the midterm is student . Suppose five students got the results below.
For student 5, four students placed higher on the midterm and lower on the final, and no student placed lower on the midterm and higher on the final, so the satisfaction is 4. For student 1, no student meets the first condition and four students meet the second one, so the satisfaction is -4.
Write a program that prints the satisfaction of every student in the section.
Input
The first line contains the number of students (). The second line contains integers: the students who placed 1st through -th on the final, each written as that student's midterm rank, in that order.
Output
Print the final exam satisfaction of each student, one per line, ordered by midterm rank from 1st to -th.