# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568494 | stevancv | Arranging Shoes (IOI19_shoes) | C++14 | 91 ms | 16532 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 <bits/stdc++.h>
#include "shoes.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
int bit[2 * N];
void Add(int x) {
for (; x < 2 * N; x += x & (-x)) bit[x]++;
}
int Get(int x) {
int ans = 0;
for (; x > 0; x -= x & (-x)) ans += bit[x];
return ans;
}
long long count_swaps(vector<int> s) {
int n = s.size() / 2;
vector<vector<int>> pa(n), pb(n);
for (int i = 0; i < 2 * n; i++) {
if (s[i] > 0) {
s[i] -= 1;
pb[s[i]].push_back(i);
}
else {
s[i] += 1;
pa[abs(s[i])].push_back(i);
}
}
ll ans = 0;
vector<array<int, 2>> p;
for (int i = 0; i < n; i++) {
for (int j = 0; j < pa[i].size(); j++) {
if (pa[i][j] > pb[i][j]) {
swap(pa[i][j], pb[i][j]);
ans += 1;
}
p.push_back({pa[i][j], pb[i][j]});
}
}
sort(p.begin(), p.end());
vector<int> all;
for (int i = 0; i < n; i++) {
all.push_back(p[i][0]);
all.push_back(p[i][1]);
}
for (int i = all.size() - 1; i >= 0; i--) {
ans += Get(all[i] + 1);
Add(all[i] + 1);
}
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... |