# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361855 | Matteo_Verz | Arranging Shoes (IOI19_shoes) | C++17 | 1096 ms | 364 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];
long long count_swaps(vector<int> s) {
map <int, int> mp;
s.insert(s.begin(), 0);
int n = s.size() - 1;
Fenwick aib(n);
for(int i = 1; i <= n; i++) {
if(mp.find(-s[i]) != mp.end()) {
rightpos[mp[-s[i]]] = i;
rightpos[i] = i;
mp.erase(-s[i]);
} else mp.insert(make_pair(s[i], i));
aib.Update(i, 1);
}
long long 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 += 1LL * aib.Query(pereche);
else ans += 1LL * (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... |