# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143454 | ChrisT | Arranging Shoes (IOI19_shoes) | C++17 | 414 ms | 138476 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<bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long ll;
const int MN = 2e5+2;
bool done[MN];
deque<int> inds[MN];
int bit[MN];
void update (int i, int v) {
for (i++;i<MN;i+=i&-i)
bit[i] += v;
}
int query (int i) {
int ret = 0;
for (i++;i>0;i^=(i&-i))
ret += bit[i];
return ret;
}
ll count_swaps (vector<int> s) {
int n = s.size(); ll ret = 0;
for (int i = 0; i < n; i++) {
inds[s[i]+100000].push_back(i);
}
for (int i = 0; i < n; i++) if (!done[i]){
int cur = s[i], ind = inds[100000-s[i]].front(); inds[100000-s[i]].pop_front(); inds[s[i]+100000].pop_front();
done[ind] = 1;
if (ind == i+1 && s[i] < 0) continue;
ret += ind - i - (s[i] < 0) - query(ind) + query(i);
update(ind,1);
}
return ret;
}
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... |