# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210998 | 2qbingxuan | Arranging Shoes (IOI19_shoes) | C++14 | 5 ms | 384 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;
long long count_swaps(std::vector<int> s) {
{
int cnt = 0;
vector<int> id(s.size());
map<int,vector<int>> mp;
for(int i = s.size()-1; i >= 0; i--) mp[s[i]].push_back(i);
for(int i = 0; i < s.size(); i++) {
if(id[i]) continue;
int S = abs(s[i]);
int a = mp[S].back(), b = mp[-S].back();
id[a] = ++cnt, id[b] = ++cnt;
mp[S].pop_back(), mp[-S].pop_back();
}
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... |