# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210951 | 2qbingxuan | Arranging Shoes (IOI19_shoes) | C++14 | 123 ms | 70776 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;
deque<int> vv[100001];
long long count_swaps(std::vector<int> s) {
{
int n = 0;
vector<int> id(s.size());
for(int i = 0; i < s.size(); i++) if(s[i] < 0) {
id[i] = n++;
vv[-s[i]].push_back(id[i]);
id[i] = id[i]*2+1;
}
for(int i = 0; i < s.size(); i++) if(s[i] > 0) {
id[i] = vv[s[i]].front() * 2 + 2;
vv[s[i]].pop_front();
}
s = id;
}
//for(int x: s) cout << x << ' '; cout << '\n';
std::reverse(s.begin(), s.end());
std::vector<int> BIT(s.size()+1);
auto query = [&BIT](int p){
int res = 0;
for(; p>0; p-=p&-p) res += BIT[p];
return res;
};
auto add = [&BIT](int p){
for(; p<BIT.size(); p+=p&-p) ++BIT[p];
};
long long ans = 0;
for(int x: s) ans += query(x-1), add(x);
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... |