ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 5419 |
문제명 | 북서풍 |
레벨 | 플래티넘 4 |
분류 |
Order Statistic Tree |
시간복잡도 | O(T * nlogn) |
인풋사이즈 | n <= 75000, T <= ??? |
사용한 언어 | Python |
제출기록 | 59548KB / 4240ms |
최고기록 | 4240ms |
해결날짜 | 2021/04/09 |
태그 |
"""Solution code for "BOJ 5419. 북서풍".
- Problem link: https://www.acmicpc.net/problem/5419
- Solution link: http://www.teferi.net/ps/problems/boj/5419
"""
import operator
import sys
from teflib import fenwicktree
def main():
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
points = [[int(x) for x in sys.stdin.readline().split()]
for _ in range(n)]
points.sort(key=operator.itemgetter(1))
compressed_y = 0
prev = points[0][1]
for point in points:
if point[1] != prev:
prev = point[1]
compressed_y += 1
point[1] = compressed_y
answer = 0
fenwick = fenwicktree.FenwickTree(n)
for _, y in sorted(points, key=lambda p: -p[0]):
answer += fenwick.query(0, y + 1)
fenwick.update(y, 1)
print(answer)
if __name__ == '__main__':
main()