# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364550 | tiberiu | Arranging Shoes (IOI19_shoes) | C++14 | 363 ms | 26732 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 <map>
#include <vector>
using namespace std;
const int MAX_N = 200001;
int aib[MAX_N];
void update(int pos, int val) {
pos++;
while (pos < MAX_N) {
aib[pos] += val;
pos += (pos & -pos);
}
}
int query(int pos) {
pos++;
int ans = 0;
while (pos) {
ans += aib[pos];
pos &= pos - 1;
}
return ans;
}
long long count_swaps(std::vector<int> s) {
map<int, vector<int>> f;
for (int i = 0; i < s.size(); i++) {
f[s[i]].push_back(i);
}
long long ans = 0;
vector<int> twin(s.size());
for (auto x : f) {
if (x.first < 0)
continue;
for (int i = 0; i < f[x.first].size(); i++) {
twin[f[x.first][i]] = f[-x.first][i];
twin[f[-x.first][i]] = f[x.first][i];
if (f[-x.first][i] > f[x.first][i])
ans++;
}
}
for (int i = 0; i < s.size(); i++) {
if (twin[i] < i) {
ans += query(i) - query(twin[i]);
update(i, 1);
update(twin[i], 1);
}
}
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... |