# Include <iostream> # include <vector> using namespace std; typedef long LL; LL merge_cnt (vector <int> & input) {int n = input. size (); if (n <= 1) return 0; LL cnt = 0; vector <int> left (input. begin (), input. begin () + n/2); // divide the vector <int> right (input. begin () + n/2, input. end (); cnt + = merge_cnt (left); cnt + = merge_cnt (right); int ai = 0, bi = 0, ci = 0; while (ai <n) {if (bi <left. size () & (ci = right. size () | left [bi] <= right [ci]) {input [ai ++] = left [bi ++];} else {cnt + = n/2-bi; // for each element of the right column, count the number of elements in left, at this time, the two columns are sorted input [ai ++] = right [ci ++] ;}} return cnt ;} int main () {int a [4] = {3, 1, 4, 2}; vector <int> input (a, a + 4); cout <merge_cnt (input) <endl; for (int I = 0; I <input. size (); I ++) {cout <input [I] <"" ;}cout <endl ;}