ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 7568 |
문제명 | 덩치 |
레벨 | 실버 5 |
분류 |
OrderStatisticTree |
시간복잡도 | O(nlogn) |
인풋사이즈 | n<=50 |
사용한 언어 | Python |
제출기록 | 33996KB / 156ms |
최고기록 | 52ms |
해결날짜 | 2021/10/05 |
"""Solution code for "BOJ 7568. 덩치".
- Problem link: https://www.acmicpc.net/problem/7568
- Solution link: http://www.teferi.net/ps/problems/boj/7568
Tags: [OrderStatisticTree]
"""
from teflib import fenwicktree
def main():
N = int(input())
heights, weights = [], []
for _ in range(N):
x, y = [int(x) for x in input().split()]
weights.append(x)
heights.append(y)
ost = fenwicktree.OrderStatisticTree(max(heights) + 1)
ranks = [None] * N
order_by_weight = sorted(range(N), key=lambda i: (-weights[i], heights[i]))
for i in order_by_weight:
h = heights[i]
ranks[i] = ost.size() - ost.count_less_than(h) - ost.count(h) + 1
ost.add(h)
print(*ranks)
if __name__ == '__main__':
main()