| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 423758 | Mazaalai | Arranging Shoes (IOI19_shoes) | C++17 | 398 ms | 27168 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>
typedef long long ll;
using namespace std;
ll ans = 0, n;
void countInv(vector <int>&s, int st, int end) {
if (st == end) return;
int mid = (st + end) / 2;
countInv(s, st, mid);
countInv(s, mid+1, end);
vector <int> tmp, A, B;
for (int i = st; i <= mid; i++) A.push_back(s[i]);
for (int i = mid+1; i <= end; i++) B.push_back(s[i]);
int inv = A.size();
A.push_back(INT_MAX);
B.push_back(INT_MAX);
ll a = 0, b = 0;
// for (int i = st; i <= end; i++) cout << s[i] << ' ';
while(a + b + 2 < A.size() + B.size()) {
if (A[a] <= B[b]) {
tmp.push_back(A[a++]);
inv--;
} else {
ans += inv;
tmp.push_back(B[b++]);
}
}
// ans += cur;
// cout << ": " << cur << ' ' << ans << '\n';
for (int i = 0; i < tmp.size(); i++) s[i+st] = tmp[i];
}
long long count_swaps(vector<int> s) {
ans = 0, n = s.size();
map <int, vector <int> > l, r;
for (int i = 0; i < n; i++) {
if (s[i] < 0)
l[-s[i]].push_back(i);
else
r[s[i]].push_back(i);
}
vector <pair <int, int> > lines;
for (auto el : l) {
int val = el.first;
vector <int> a = el.second, b = r[val];
for (int i = 0; i < a.size(); i++) {
int x = a[i], y = b[i];
if (x > y) ans++;
lines.push_back({x, y});
}
}
int cur = 0;
sort(lines.begin(), lines.end());
for (int i = 0; i < lines.size(); i++) {
int a, b;
tie(a, b) = lines[i];
s[a] = s[b] = cur++;
}
// for (int i = 0; i < n; i++) cout << s[i] << ' ';
// cout << "\n";
// cout << ans << " : ans\n";
countInv(s, 0, n - 1);
// for (int i = 0; i < n; i++) cout << s[i] << ' ';
// cout << "\n";
// cout << ans << " : ans\n";
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... | ||||
