0788

command
v0.0.0-...-0b623e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 2 Imported by: 0

README

788. 逆序对的数量

题目

给定一个长度为 $n$ 的整数数列,请你计算数列中的逆序对的数量。

逆序对的定义如下:对于数列的第 $i$ 个和第 $j$ 个元素,如果满足 $i < j$ 且 $a[i] > a[j]$,则其为一个逆序对;否则不是。

输入格式

第一行包含整数 $n$,表示数列的长度。

第二行包含 $n$ 个整数,表示整个数列。

输出格式

输出一个整数,表示逆序对的个数。

数据范围

$1 \le n \le 100000$,

数列中的元素的取值范围 $[1,10^9]$。

输入样例:

6
2 3 4 5 6 1

输出样例:

5

题解

前置题目:0787

前置知识:归并排序

本题知识:基础算法-归并排序

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL