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 <cstdio>
#include <cassert>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <stack>
#include <map>
#include "shoes.h"
using namespace std;
const int N = 2e5 + 15;
int n, a[N];
map <int, bool> used;
map <int, stack <int> > ord;
long long count_swaps(vector<int> s) {
n = s.size();
long long ans = 0;
for(int i = 0; i < n; ++i)
a[i + 1] = s[i];
for(int i = n; i; --i)
ord[a[i]].push(i);
for(int i = 1; i < n; ++i) {
if(ord[a[i]].empty() || ord[a[i]].top() != i)
continue;
ord[a[i]].pop();
int j = ord[-a[i]].top();
ord[-a[i]].pop();
if(a[i] < 0)
ans += j - i - 1;
else
ans += j - i;
}
return ans;
}
# | 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... |