#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <ctime> #include <map> #include <set> #define EPS 1e-12///#define M 1000100///# Define LL __int64#define ll long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero ( x) ((Fabs (x) <eps)? 0:x) using namespace std;const int maxn = 30100; LL A[MAXN]; LL TEMP[MAXN]; ll Sum;struct node{ll Y1; LL Y2; int id;} F[maxn];void Merge (LL a[], int l, int mid, int r) {int begin1 = l; int end1 = mid; int begin2 = mid+1; int end2 = r; int k = 0; while (begin1 <= end1 && begin2 <= end2) {if (A[begin1] < a[begin2]) {temp[k+ +] = a[begin1]; begin1++; Sum + = begin2-(mid+1); } else {temp[k++] = a[Begin2]; begin2++; }} while (Begin1 <= end1) {temp[k++] = a[begin1]; begin1++; sum + = End2-mid; } while (Begin2 <= end2) {temp[k++] = a[begin2]; begin2++; } for (int i = l; I <= R; i++) A[i] = temp[i-l];} void MergeSort (LL a[], int l, int r) {int mid = (l+r) >>1; if (L < R) {MergeSort (A, L, mid); MergeSort (A, mid+1, R); Merge (A, L, Mid, R); }}
Merge sort to find the number of reverse order