1 // 687950 zhuli19901106 1348 Accepted 点击此处查看所有case的执行结果 1800KB 1093B 100MS
2 // 201401302316
3 #include <cstdio>
4 using namespace std;
5
6 const int MAXN = 100005;
7 int a[MAXN];
8 int n;
9 long long int res;
10 int tmp[MAXN];
11
12 void merge_sort_recursive(int a[], int ll, int rr)
13 {
14 if (ll >= rr) {
15 return;
16 }
17 int mm;
18 mm = (ll + rr) / 2;
19 merge_sort_recursive(a, ll, mm);
20 merge_sort_recursive(a, mm + 1, rr);
21
22 int i, j, k;
23
24 i = ll;
25 j = mm + 1;
26 k = ll;
27 while (true) {
28 if (i <= mm) {
29 if (j <= rr) {
30 if (a[i] <= a[j]) {
31 tmp[k++] = a[i++];
32 } else {
33 tmp[k++] = a[j++];
34 res += mm - i + 1;
35 }
36 } else {
37 tmp[k++] = a[i++];
38 }
39 } else {
40 if (j <= rr) {
41 tmp[k++] = a[j++];
42 } else {
43 break;
44 }
45 }
46 }
47 for (i = ll; i <= rr; ++i) {
48 a[i] = tmp[i];
49 }
50 }
51
52 int main()
53 {
54 int i;
55
56 while (scanf("%d", &n) == 1) {
57 for (i = 0; i < n; ++i) {
58 scanf("%d", &a[i]);
59 }
60 res = 0;
61 merge_sort_recursive(a, 0, n - 1);
62 printf("%lld\n", res);
63 }
64
65 return 0;
66 }