我的两次提交:
两份代码唯一的区别在第24行(下面被我注释掉的地方)
#include <bits/stdc++.h>
#define int long long
#define ls ch[x][0]
#define rs ch[x][1]
using namespace std;
typedef pair<int,int> pii;
int id[1000005], n;
map <pii, pii> mp;
int a[2][1000005], b[2][1000005];
int pos[1000005], fl[1000005];
bool check () {
scanf("%lld", &n);
bool flag = (n > 50000);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[0][i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[1][i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &b[0][i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &b[1][i]);
for (int i = 1; i <= n; i++) {
pos[a[0][i]] = i;
//fl[a[0][i]] = i;
}
for (int i = 1; i <= n; i++) {
int x = b[0][i], y = b[1][i];
if (pos[x]) {
if (a[1][pos[x]] != y || abs(pos[x] - i) & 1) {
return false;
}
id[pos[x]] = i;
}else if (pos[y]) {
if (a[1][pos[y]] != x || !abs(pos[y] - i) & 1){
return false;
}
id[pos[y]] = i;
}else
return false;
}
return true;
}
inline int lowbit (int x) {
return x & (-x);
}
struct Tree_Array {
int tr[1000005];
void ins (int x, int k) {
for (int i = x; i <= n; i += lowbit(i))
tr[i] += k;
return;
}
int query (int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i))
res += tr[i];
return res;
}
}T;
void calc () {
int ans = 0;
for (int i = n; i >= 1; i--) {
ans += T.query(id[i] - 1);
T.ins(id[i], 1);
}
printf("%lld\n", ans);
return;
}
signed main () {
if (!check()) {
puts("dldsgay!!1");
return 0;
}
calc();
return 0;
}
注释掉这一行,就能AC。
不注释,就会WA。
但是,fl数组在整片代码中,除了定义和第24行,没有出现过。
也就是说,第24行完全是无效的。但它出现了就是会WA。
求解(因为这个调了一个小时QAQ)