You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
643 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

北京航空航天大学教授讲解, 非常清楚
https://www.ixigua.com/6852470382776025603?id=6852450934203613710
逆序对有三部分组成:
S1:两个数都出现在左侧
S2:两个数都出现在右侧
S3两个数分别出现在左侧和右侧
观察整个归并的过程发现其实从最底层起每个S3其实就是由S1和S2“贡献”后出现的就是说我们如果一直记录了S3那么就是S1+S2+S3
而在q[i]>q[j]时tmp[k++]=q[j++]就是逆序的过程就是需要记录的S3.而这个值是 ans+=mid-i+1;
可以用数列: 4 6 8 3 5 进行模拟
https://www.acwing.com/solution/content/18376/