2
1 4
3 2
1 3
4 2
我的 AC 代码输出 0,但这组数据似乎无解?
好像输入只能变成
2 3
4 1
附上代码
#include<bits/stdc++.h>
using namespace std;
const int N = int(1e6) + 10;
int a[N], b[N], pos[N << 1][2], tr[N], n;
int Lowbit(int x) {return x & (-x);}
void Modi(int x)
{
for(int i = x; i <= n; i += Lowbit(i)) tr[i]++;
}
int Ask(int x)
{
int res = 0;
for(int i = x; i; i -= Lowbit(i)) res += tr[i];
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for(int i = 0; i < 2; i++)
for(int j = 1; j <= n; j++)
if((i + j) & 1) cin >> a[j];
else cin >> b[j];
for(int i = 0; i < 2; i++)
for(int j = 1; j <= n; j++)
{
int x;
cin >> x;
pos[x][(i + j) & 1] = j;
}
for(int i = 1; i <= n; i++)
{
if(pos[a[i]][1] == 0)
{
cout << "dldsgay!!1";
return 0;
}
else a[i] = pos[a[i]][1];
if(pos[b[i]][0] == 0)
{
cout << "dldsgay!!1";
return 0;
}
else b[i] = pos[b[i]][0];
}
long long res = 0;
for(int i = 1; i <= n; i++)
{
res += Ask(n) - Ask(a[i]);
Modi(a[i]);
}
cout << res;
return 0;
}
貌似没有判断两个数组必须完全一样。