# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201416 | khulegub | Arranging Shoes (IOI19_shoes) | C++14 | 13 ms | 9976 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>
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define ll(x) (x*2) + 1
#define rr(x) (x*2) + 2
using namespace std;
typedef long long i64;
int ft[100005];
int query(int x){
int sm = 0;
while (x){
sm += ft[x];
x -= x & (-x);
}
return sm;
}
int query(int l, int r){
int ll = 0;
if (l != 0) ll = query(l - 1);
return query(r) - ll;
}
int update(int x, int v){
while (x){
ft[x] += v;
x += x & (-x);
}
}
bool taken[100005];
vector<int> maap_l[100005], maap_r[100005];
i64 count_swaps(std::vector<int> s) {
i64 ans = 0LL;
int n = s.size();
for (int i = n - 1; i >= 0; i--){
if (s[i] < 0) maap_l[s[i] * -1].pb(i);
else maap_r[s[i]].pb(i);
}
for (int i = 0; i < n; i++){
if (!taken[i]){
int tmp;
if (s[i] < 0){
maap_r[s[i]].pop_back();
tmp = maap_r[s[i]].back();
}
else{
maap_l[s[i]].pop_back();
tmp = maap_l[s[i]].back();
}
taken[tmp] = 1;
if (s[i] < 0){
ans += tmp - i - 1;
}
else{
ans += tmp - i;
}
ans -= query(i + 1, tmp + 1);
update(tmp + 1, 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... |