mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-30 00:37:37 +08:00
22 lines
1.4 KiB
HTML
22 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1009. Triple Inversions (35)</h1>
|
|
<div id="problemContent">
|
|
<p>Given a list of N integers A<sub>1</sub>, A<sub>2</sub>, A<sub>3</sub>,...A<sub>N</sub>, there's a famous problem to count the number of inversions in it. An inversion is defined as a pair of indices i < j such that A<sub>i</sub> > A<sub>j</sub>.</p>
|
|
<p>Now we have a new challenging problem. You are supposed to count the number of <b>triple inversions</b> in it. As you may guess, a triple inversion is defined as a triple of indices i < j < k such that A<sub>i</sub> > A<sub>j</sub> > A<sub>k</sub>. For example, in the list {5, 1, 4, 3, 2} there are 4 triple inversions, namely (5,4,3), (5,4,2), (5,3,2) and (4,3,2). To simplify the problem, the list A is given as a permutation of integers from 1 to N.</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case. For each case, the first line gives a positive integer N in [3, 10<sup>5</sup>]. The second line contains a permutation of integers from 1 to N and each of the integer is separated by a single space.</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each case, print in a line the number of triple inversions in the list.</p>
|
|
<b>Sample Input:</b><pre>
|
|
22
|
|
1 2 3 4 5 16 6 7 8 9 10 19 11 12 14 15 17 18 21 22 20 13
|
|
</pre>
|
|
<b>Sample Output:</b><pre>
|
|
8
|
|
</pre>
|
|
</div> |