#p187. 例题4.2.4 逆序对
例题4.2.4 逆序对
题目描述
给定一个整数序列,如果存在 并且,那么我们称之为逆序对。
求逆序对的数目
输入格式
第一行为n,表示序列长度;
接下来的n行,第i+1行表示序列中的第i个数。
输出格式
所有逆序对总数.
样例数据
input
4
3
2
3
2
output
3
数据规模与约定
保证
时间限制:
空间限制:
给定一个整数序列a1,a2,…,an,如果存在i<j 并且ai>aj,那么我们称之为逆序对。
求逆序对的数目
第一行为n,表示序列长度;
接下来的n行,第i+1行表示序列中的第i个数。
所有逆序对总数.
input
4
3
2
3
2
output
3
保证1≤n,ai≤105
时间限制:1s
空间限制:256MB
By signing up a code-fans universal account, you can submit code and join discussions in all online judging services provided by us.