목차

덩치

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()