// SPN Set:https://www.luogu.com.cn/article/jouhmyjq
const int N = 2e5 + 5;
int n; i64 ans;
spn_multiset<int> dfs() {
int x; cin >> x;
if (x != 0) {
spn_multiset<int> S;
S.insert(x); return S;
}
auto a = dfs(); auto b = dfs();
if (a.size() > b.size()) a.swap(b);
i64 x1 = 0, x2 = 0;
for (int i : a) {
x1 += b.lower_bound(i);
x2 += b.size() - b.upper_bound(i);
}
ans += min(x1, x2);
for (int i : a) b.insert(i);
return b;
}
void _main() {
cin >> n, dfs(), cout << ans;
} 剪贴板
剪贴板 tvclfpye
剪贴板信息
剪贴板信息
- 发布
- 收录
- 更新