# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361842 | Matteo_Verz | Arranging Shoes (IOI19_shoes) | C++17 | 45 ms | 8284 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;
const int N = 1e5;
class Fenwick {
private:
vector <int> a;
int lsb(int i) {
return (i & (-i));
}
public:
Fenwick(int n) {
a.resize(1 + n);
}
void Update(int pos, int val) {
for(; pos < a.size(); pos += lsb(pos))
a[pos] += val;
}
int Query(int pos) {
int ans(0);
for(; pos > 0; pos -= lsb(pos))
ans += a[pos];
return ans;
}
};
int rightpos[1 + N];
int lastv[1 + N];
long long count_swaps(vector<int> s) {
s.insert(s.begin(), 0);
int n = s.size() - 1;
Fenwick aib(n);
for(int i = 1; i <= n; i++) {
int val = abs(s[i]);
if(lastv[val] != 0) {
rightpos[lastv[val]] = i;
rightpos[i] = i;
lastv[val] = 0;
} else {
lastv[val] = i;
}
aib.Update(i, 1);
}
int ans(0);
for(int i = 1; i <= n; i++) {
int pereche = rightpos[i];
if(pereche != i) {
aib.Update(i, -1); aib.Update(pereche, -1);
if(s[i] < 0) ans += aib.Query(pereche);
else ans += aib.Query(pereche) + 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... |