# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
433206 | kostia244 | Arranging Shoes (IOI19_shoes) | C++17 | 1083 ms | 1856 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;
using ll = long long;
#define all(x) begin(x), end(x)
long long count_swaps(std::vector<int> s) {
ll res = 0;
for(int i = 0; i < s.size(); i+=2) {
int j = i+1;
while(s[j] != -s[i]) j++;
for(; j-1 > i; j--) swap(s[j], s[j-1]), res++;
if(s[i] > 0) swap(s[i], s[i+1]), res++;
}
return res;
for(auto &i : s) i *= -1;
int n = s.size()/2;
vector<ll> fen(2*n+1);
auto add = [&](int x) {
for(; x <= 2*n; x += x&-x) fen[x]++;
};
auto get = [&](int x) {
int res = 0;
add(x);
for(; x; x -= x&-x)
res += fen[x];
return res;
};
vector<int> b(2*n);
map<int, vector<int>> ass;
for(int i = 0; i < 2*n; i++) ass[s[i]].push_back(i);
for(auto &[a, b] : ass) reverse(all(b));
vector<int> v(2*n, -69);
for(int j = 0, i = 0; i < 2*n; i++) if(s[i] >= 0) {
v[i] = ++j;
v[ass[-s[i]].back()] = ++j;
ass[-s[i]].pop_back();
}
for(auto &i : v) cout << i << " "; cout << endl;
for(int i = 0; i < 2*n; i++) b[v[i]-1] = i+1;
int cur = 0;
for(auto i : b) {
//cout << _ << " " << __ << " " << i << endl;
//cout << i << " ";
res += ++cur - get(i);
//cout << i << " " << res << endl;
}
return res;
}
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... |