# P6687 论如何玩转 Excel 表格(逆序对)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn=2e6+10;
int n,a[3][maxn],b[3][maxn],flag=1,id[maxn],temp[maxn],ans;
typedef pair<int,int>p;
p vis[maxn];
{
long long s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void merge_sort(int l,int mid,int r)
{
int p1=l,p2=mid+1,top=l-1;
while( p1<=mid&&p2<=r )
{
if( id[p1]>id[p2] )	temp[++top]=id[p2++],ans+=(mid-p1+1);
else	temp[++top]=id[p1++];
}
while( p1<=mid )	temp[++top]=id[p1++];
while( p2<=r )	temp[++top]=id[p2++];
for(int i=l;i<=r;i++)	id[i]=temp[i];
return;
}
void merge(int l,int r)
{
if( l>=r )	return;
int mid=l+r>>1;
merge(l,mid);
merge(mid+1,r);
merge_sort(l,mid,r);
}
signed main()
{
for(int i=1;i<=2;i++)
for(int j=1;j<=n;j++)
for(int i=1;i<=2;i++)
for(int j=1;j<=n;j++)
{
vis[ b[i][j] ]=p(i,j);
}
for(int i=1;i<=n;i++)//遍历每一列
{
int q=a[1][i],w=a[2][i];
if( vis[q].s!=vis[w].s )	flag=0;//不在一列,不符合
int cha=abs(vis[q].s-i);
if( cha%2==1&&vis[q].f==1 )	flag=0;
if( cha%2==0&&vis[q].f==2 )	flag=0;
id[i]=vis[q].s;
}
if( flag==0 )	cout << "dldsgay!!1";
else
{
merge(1,n);
cout << ans;
}
}
07-27 46
07-18 5028

01-06 2222
06-11 1万+
05-31 7650
09-28 215
08-16 264
09-12 1246