paper plane fly away
鏈接:https://ac.nowcoder.com/acm/contest/903/E
來源:牛客網
There are n boys, indexed from 1 to n, and n girls indexed from n+1 to 2n.
One day, they have a party together. The girls are seated in the first row, and the boys sit in the second row. They take their seat in such a way, that a boy sit just behind a girl, and boy indexed 1 sit on the leftmost chair, 2 sit on the second, etc.
Each boy has a girl he likes,and he may make contact to his sweetheart, by writing down what he wants to tell her on a piece of paper, and makes it a paper plane, which he will throw directly at her. You may assume that the plane will go in a straight line.
But, the trouble occurs, when two paper plane collide in the air and drop halfway. Obviously, this will be extremely awkward. So each boy wants to know, if he throws his paper plane, how many paper planes have the potential to collide with it halfway.
It’s guaranteed that each girl is the sweetheart of exactly one boy.
輸入描述:
The first line contains a single integer n.
Then n lines follow, the i-th of which contains two integers, the index of the girl seated in front of the i-th boy and the girl he likes.
1
≤
n
≤
10
5
1≤n≤105
輸出描述:
Output n lines, the i-th of which contains one integer, the number of planes that may collide with i-th boy’s plane.
示例1
輸入
復制
5
7 9
6 6
8 10
9 7
10 8
輸出
復制
3
2
2
3
2
這個題,我在場時的思路是把喜歡的人的連用圖來存起來,然后之后沒飛一個飛機就行和列去掃描,,,,思路比較清晰,但是實在是太慢了
以下是題解:
用樹狀數組做,快速求得前i項和,正反插入兩次,求得逆序對的數量和
參考了一位大佬寫的代碼
總結
以上是生活随笔為你收集整理的paper plane fly away的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python3爬虫-中国最好大学排名
- 下一篇: Wonderware fsGatewa