归并排序
#include<iostream>
#include<cstdio>
#include<map>
//#include<bits/stdc++.h>
using namespace std;
int tmp[100010],b[100010];
map<int,int>a;
map<int,int>::iterator it;
void meger(int l,int mid,int r)
{
int i,j,k,cnt=0;
i=l;j=mid+1;k=l;
while(i<=mid&&j<=r)
{
if(b[i]>b[j])
{
a[b[i]]++;
cnt++;
tmp[k++]=b[j++];
}
else
{
tmp[k++]=b[i++];
if(i<=mid)
a[b[i]]+=cnt;
}
}
while(i<=mid)
{
if(i+1<=mid)
a[b[i+1]]+=cnt;
tmp[k++]=b[i++];
}
while(j<=r) tmp[k++]=b[j++];
for(i=l;i<=r;i++) b[i]=tmp[i];
}
void megersort(int l,int r)
{
if(r<=l) return ;
int mid=(l+r)>>1;
megersort(l,mid);
megersort(mid+1,r);
meger(l,mid,r);
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
a[b[i]]=0;
}
megersort(1,n);
for(it=a.begin();it!=a.end();it++) cout<<it->first<<" "<<it->second<<endl;
return 0;
}