# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583516 | lcj | Arranging Shoes (IOI19_shoes) | C++17 | 348 ms | 77512 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 LSOne(s) ((s) & -(s))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
struct FenwickTree {
vector<ll> ft;
FenwickTree(int n) : ft(n+1) {}
ll rsq(int i) {
ll su = 0;
for (; i > 0; i -= LSOne(i)) {
su += ft[i];
}
return su;
}
void update(int i, ll dv) {
for (; i < (int)ft.size(); i += LSOne(i)) {
ft[i] += dv;
}
}
};
ll count_swaps(std::vector<int> s) {
FenwickTree ft(s.size());
map<int, queue<int>> open;
ll csum = 0;
vector<int> mypartner(s.size());
for (int i = 0; i < s.size(); i++)
{
if (open.find(-s[i]) != open.end() && !open[-s[i]].empty()) {
int j = open[-s[i]].front();
open[-s[i]].pop();
mypartner[j] = i;
mypartner[i] = j;
csum += (s[i] < 0);
}
else {
if (!open.count(s[i])) {
open[s[i]] = {};
}
open[s[i]].push(i);
}
}
for (int i = 0; i < s.size(); i++)
{
int j = mypartner[i];
if (j < i) continue;
csum += (j+ft.rsq(j+1))-(i+ft.rsq(i+1))-1;
ft.update(1, 1);
ft.update(j+1, -1);
}
return csum;
}
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... |