ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 17131 |
문제명 | 여우가 정보섬에 올라온 이유 |
레벨 | 플래티넘 4 |
분류 |
Order Statistic Tree |
시간복잡도 | O(nlogn) |
인풋사이즈 | n <= 200,000 |
사용한 언어 | Python |
제출기록 | 71780KB / 1700ms |
최고기록 | 1700ms |
해결날짜 | 2021/04/08 |
태그 |
""""Solution code for "BOJ 17131. 여우가 정보섬에 올라온 이유"
- Problem link: https://www.acmicpc.net/problem/17131
- Solution link: http://www.teferi.net/ps/problems/boj/17131
"""
import itertools
import operator
import sys
from teflib import fenwicktree
MOD = 10**9 + 7
def main():
N = int(sys.stdin.readline())
stars = []
for _ in range(N):
x, y = [int(x) for x in sys.stdin.readline().split()]
stars.append((x, y))
min_x = min(x for x, y in stars)
fenwick = fenwicktree.FenwickTree(max(x for x, y in stars) - min_x + 1)
answer = 0
total_point_count = 0
stars.sort(reverse=True, key=operator.itemgetter(1))
for _, group in itertools.groupby(stars, key=operator.itemgetter(1)):
compressed_x = [x - min_x for x, y in group]
for cx in compressed_x:
up_left_point_count = fenwick.query(0, cx)
up_right_point_count = (total_point_count - up_left_point_count -
fenwick.get(cx))
answer += up_left_point_count * up_right_point_count
for cx in compressed_x:
fenwick.update(cx, 1)
total_point_count += 1
print(answer % MOD)
if __name__ == '__main__':
main()