# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
415259 | peuch | Arranging Shoes (IOI19_shoes) | C++17 | 100 ms | 16784 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;
bool cmp(pair<int, int> a, pair<int, int> b){
return a.first + a.second < b.first + b.second;
}
long long count_swaps(std::vector<int> s) {
int n = s.size() / 2;
vector<vector<int> > colors[2] = {vector<vector<int> >(n + 1), vector<vector<int> >(n + 1)};
vector<int> ids(2 * n);
vector<int> bit(2 * n + 1);
for(int i = 0; i < 2 * n; i++)
colors[(s[i] < 0) ? 0 : 1][abs(s[i])].push_back(i);
vector<pair<int, int> > ord;
for(int i = 0; i < colors[0].size(); i++)
for(int j = 0; j < colors[0][i].size(); j++)
ord.push_back(make_pair(colors[0][i][j], colors[1][i][j]));
sort(ord.begin(), ord.end(), cmp);
for(int i = 0; i < ord.size(); i++){
ids[ord[i].first] = 2 * i;
ids[ord[i].second] = 2 * i + 1;
}
long long ans = 0;
for(int i = 2 * n - 1; i >= 0; i--){
int id = ids[i] + 1;
while(id > 0){
ans += bit[id];
id -= -id&id;
}
id = ids[i] + 1;
while(id < 2 * n + 1){
bit[id]++;
id += -id&id;
}
}
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... |