Files
python/TangDou/Doc/逆序对.txt
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

13 lines
655 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

北京航空航天大学教授讲解, 非常清楚
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/