# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395331 | ja_kingy | Arranging Shoes (IOI19_shoes) | C++14 | 60 ms | 12688 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"
using namespace std;
const int mxN = 1e5+10;
vector<int> of_type[2*mxN];
int bit[mxN];
void upd(int x) {for (x++; x<mxN; x+=x&-x) bit[x]++;}
int qry(int x) {
int res = 0;
for (x++; x; x-=x&-x) res += bit[x];
return res;
}
long long count_swaps(std::vector<int> s) {
long long ans = 0;
for (int i = s.size(); i--;) {
of_type[s[i]+mxN].push_back(i);
}
for (int i = 0; i < s.size(); ++i) {
if (i == of_type[s[i]+mxN].back()) {
int x = of_type[mxN-s[i]].back();
ans += x - i + (s[i] > 0) - qry(x) + qry(i) - 1;
upd(x);
of_type[s[i]+mxN].pop_back();
of_type[mxN-s[i]].pop_back();
}
}
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... |