标签:while amp clu scan 代码 == bit else namespace
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int a[N],b[N];
ll ans = 0;
#define sc scanf
#define pr printf
#define rep(i,x,y) for(int i = x;i <= y;i++)
#define rvp(i,x,y) for(int i = y;i >= x;i--)
void merge(int l,int r)
{
if(l == r) return ;
int m = (l+r) >> 1;
merge(l,m);
merge(m+1,r);
int p1=l,p2 = m + 1;
int cur = l;
while(p1 <= m || p2 <= r)
{
if(p2 > r|| p1 <= m && a[p1] <= a[p2])
{
b[cur++] = a[p1];
p1++;
}
else{
b[cur++] = a[p2];
p2++;
ans += (m - p1 + 1);
}
}
rep(i,l,r) a[i] = b[i];
}
int main()
{
int n;
while(~sc("%d",&n))
{
rep(i,1,n) sc("%d",&a[i]);
ans = 0;
merge(1,n);
rep(i,1,n) pr("%d ",a[i]);
puts("");
pr("%lld\n",ans);
}
return 0;
}
标签:while amp clu scan 代码 == bit else namespace
原文地址:https://www.cnblogs.com/mch5201314/p/11345836.html