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>
using namespace std;
long long count_swaps(vector<int> s) {
int n=s.size();
vector<int> cnt[(int)2*n+5];
vector<int> used(2*n+5, 0);
vector<bool> visited(2*n+5, false);
long long comp=0;
for (int i = 0; i < n; ++i)
{
cnt[s[i]+n].push_back(i);
}
for (int i = 0; i < n; ++i)
{
if (visited[i]) continue;
int recherche=(-1*s[i])+n;
if (s[i]<0) comp--;
//cout << recherche << " " << n << " ";
comp+=cnt[recherche][used[recherche]]-i;
//cout << cnt[recherche][used[recherche]] << endl;
visited[cnt[recherche][used[recherche]]]=true;
used[recherche]++;
used[s[i]+n]++;
}
cout << endl;
return comp;
}
| # | 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... |