1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| """ # @Time : 2020/10/14 # @Author : Jimou Chen """
num = [0 for i in range(100)] temp = [0 for i in range(100)] count = 0
def merge(low, high, mid): left = low right = mid + 1 k = low global count
while left <= mid and right <= high: if num[left] > num[right]: temp[k] = num[right] k += 1 right += 1 count += mid - left + 1 else: temp[k] = num[left] k += 1 left += 1
while left <= mid: temp[k] = num[left] k += 1 left += 1
while right <= high: temp[k] = num[right] k += 1 right += 1
for i in range(low, high + 1): num[i] = temp[i]
def merge_sort(low, high): if low >= high: return
mid = (high + low) // 2 merge_sort(low, mid) merge_sort(mid + 1, high)
merge(low, high, mid)
if __name__ == '__main__': num = list(map(int, input().split())) merge_sort(0, len(num) - 1) print(count)
|