Files
PAT/html/t1009.html
T

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 &lt; j such that A<sub>i</sub> &gt; 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 &lt; j &lt; k such that A<sub>i</sub> &gt; A<sub>j</sub> &gt; 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>