【Ultra-QuickSort】
链接:https://ac.nowcoder.com/acm/contest/1001/E
来源:牛客网
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence
9 1 0 5 4 ,
Ultra-QuickSort produces the output
0 1 4 5 9 .
Your task is to determine how many swap operations Ultra-QuickSort needs to perform in order to sort a given input sequence.
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N=501000;
#define ll long long
ll n,m,i,j,k,a[N],b[N],cnt;
void merge(ll a[],ll l,ll r)
{
if (r-l<1)
return ;
ll mid=(l+r)>>1;
merge(a,l,mid);
merge(a,mid+1,r);
ll i=l,j=mid+1;
for (ll k=l;k<