# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758794 | Blagoj | Arranging Shoes (IOI19_shoes) | C++17 | 536 ms | 149452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
struct FenwickTree {
vector<ll> fwt;
FenwickTree(int n) {
fwt.resize(n);
}
void add(int n) {
for (n++; n < fwt.size(); n += n & -n) {
fwt[n]++;
}
}
ll get(int n) {
ll s = 0;
for (n++; n > 0; n -= n & -n) {
s += fwt[n];
}
return s;
}
};
long long count_swaps(vector<int> s) {
map<int, queue<int>> mp;
for (int i = 0; i < s.size(); i++) {
mp[s[i]].push(i);
}
int d[s.size() + 2], cur = 1;
memset(d, 0, sizeof(d));
for (int i = 0; i < s.size(); i++) {
if (d[i] != 0) continue;
if (s[i] < 0) {
d[i] = cur;
mp[s[i]].pop();
d[mp[-s[i]].front()] = cur + 1;
mp[-s[i]].pop();
}
else {
d[i] = cur + 1;
mp[s[i]].pop();
d[mp[-s[i]].front()] = cur;
mp[-s[i]].pop();
}
cur += 2;
}
ll ans = 0;
FenwickTree fwt(s.size() + 5);
for (int i = s.size() - 1; i >= 0; i--) {
ans += fwt.get(d[i] - 1);
fwt.add(d[i]);
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |