| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1314261 | haithamcoder | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update
> ordered_set;
long long count_swaps(std::vector<int> a) {
ll n = a.size() / 2;
map<ll, ll> mp;
for (ll i = 0; i < 2 * n; i++) {
mp[a[i]] = i;
}
ordered_set s;
for (ll i = 0; i < 2 * n; i++) {
s.insert(i);
}
ll res = 0;
while (s.size()) {
auto x = *s.begin();
ll sz = a[x];
ll other = mp[-sz];
res += s.order_of_key(other) - (sz < 0);
s.erase(mp[sz]);
s.erase(mp[-sz]);
}
return res;
}
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> S(2 * n);
for (int i = 0; i < 2 * n; i++)
assert(1 == scanf("%d", &S[i]));
fclose(stdin);
long long result = count_swaps(S);
printf("%lld\n", result);
fclose(stdout);
return 0;
}
