# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047288 | Onur_Ilgaz | Arranging Shoes (IOI19_shoes) | C++17 | 273 ms | 146620 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;
struct fw {
int n;
vector <int> t;
fw(int size): n(size), t(n + 1) {}
void update(int ind, int x) {
while(ind <= n) {
t[ind] += x;
ind += ind & (-ind);
}
}
int query(int ind) {
int ans = 0;
while(ind) {
ans += t[ind];
ind -= ind & (-ind);
}
return ans;
}
};
long long count_swaps(std::vector<int> s) {
fw t(s.size());
map <int, queue<int> > mp;
int ans = 0;
for(int i = 0; i < s.size(); i++) {
if(!mp[-s[i]].empty()) {
int ind = mp[-s[i]].front();
t.update(ind + 2, 1);
t.update(i + 1, -1);
ind += t.query(ind + 1);
// cout << i << " " << ind << "\n";
mp[-s[i]].pop();
ans += (i - ind) - (s[i] > 0);
}
else {
mp[s[i]].push(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... |