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"
using namespace std;
typedef long long int ll;
long long count_swaps(std::vector<int> s) {
int n = s.size();
vector<ll> open = vector<ll>(n+1, 0);
vector<bool> openR = vector<bool>(n+1, false);
ll copen = 0;
ll inv = 0;
ll stol = 0;
ll dtol = 0;
for(int i=0; i < n; ++i) {
ll cs = (s[i] > 0) ? s[i] : -s[i];
if(s[i] > 0) {
if(open[cs] > 0 and !openR[cs]) {
copen--;
open[cs]--;
stol += open[cs];
dtol += copen-open[cs];
if(open[cs] == 0) {
}
}
else {
stol += open[cs];
dtol += copen-open[cs];
open[cs]++;
copen++;
if(open[cs] == 1) {
openR[cs] = true;
}
}
}
else {
if(open[cs] > 0 and openR[cs]) {
copen--;
open[cs]--;
stol += open[cs];
dtol += copen-open[cs];
inv++;
if(open[cs] == 0) {
openR[cs] = false;
}
}
else {
stol += open[cs];
dtol += copen-open[cs];
open[cs]++;
copen++;
}
}
}
return dtol+stol/2+inv;
}
# | 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... |