ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 5012 |
문제명 | 불만 정렬 |
레벨 | 플래티넘 3 |
분류 |
Inversion Counting |
시간복잡도 | O(nlogn) |
인풋사이즈 | n <= 100,000 |
사용한 언어 | Python |
제출기록 | 48536KB / 1108ms |
최고기록 | 1108ms |
해결날짜 | 2021/04/07 |
"""Solution code for "BOJ 5012. 불만 정렬"
- Problem link: https://www.acmicpc.net/problem/5012
- Solution link: http://www.teferi.net/ps/problems/boj/5012
"""
from teflib import fenwicktree
def main():
N = int(input())
a = [int(x) for x in input().split()]
nums = fenwicktree.OrderStatisticTree(N)
inversions = fenwicktree.OrderStatisticTree(N)
answer = 0
for a_i in reversed(a):
answer += inversions.count_less_than(a_i)
inversion_count = nums.count_less_than(a_i)
inversions.add(a_i, inversion_count)
nums.add(a_i, 1)
print(answer)
if __name__ == '__main__':
main()