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;
typedef long long ll;
typedef pair<ll,ll> pii;
ll count_swaps(vector<int> s) {
ll n = s.size();
map<ll,queue<ll>> m;
for(ll i=0;i<n;i++)
m[s[i]].push(i);
set<ll> erased;
ll res = 0;
for(ll i=0;i<n;i++)
{
if(erased.count(i)) continue;
m[s[i]].pop();
ll j = m[-s[i]].front();
m[-s[i]].pop();
res += j-i-1;
if(s[i]>0) res++;
for(ll k=i+1;k<j;k++)
if(erased.count(k)) res--;
erased.insert(i);
erased.insert(j);
}
return res;
}
# | 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... |