# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051622 | Tob | Arranging Shoes (IOI19_shoes) | C++14 | 33 ms | 15644 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 F first
#define S second
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int fen[N];
vector <int> v[N];
void add(int x, int val) {for (x++; x < N; x += x & -x) fen[x] += val;}
int get(int x) {int out = 0; for (x++; x; x -= x & -x) out += fen[x]; return out;}
ll count_swaps(vector <int> a) {
int n = a.size();
vector <int> pa(n, -1);
for (int i = 0; i < n; i++) v[a[i]+n/2].push_back(i);
for (int i = 0; i <= n; i++) {
for (int j = 0; j < v[i].size(); j++) pa[min(v[i][j], v[n-i][j])] = max(v[i][j], v[n-i][j]);
}
ll res = 0;
for (int i = 0; i < n; i++) {
if (pa[i] == -1) continue;
res += pa[i]-i-(a[i] < 0) - get(pa[i])+get(i);
add(pa[i], 1);
}
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... |