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;
map<int , vector<int> >num;
vector<pair<int , int> >erg;
int vis[200000] , pref[200000];
long long count_swaps(vector<int> s) {
long long menge = s.size() , be , en , re = 0;
for(int i = menge - 1 ; i >= 0 ; i--){
num[s[i]].push_back(i);
}
for(int i = 0 ; i < menge ; i++){
if(vis[i] == 1){
continue;
}
be = i;
en = num[s[i] * -1][num[s[i] * -1].size() - 1];
num[s[i] * -1].pop_back();
num[s[i]].pop_back();
if(be > en){
swap(be , en);
}
for(int j = be ; j <= en ; j++){
pref[j]++;
}
vis[be] = 1;
vis[en] = 1;
be += pref[be];
en += pref[en];
if(s[i] > 0){
re++;
}
re += (en - be - 1);
}
return re;
}
# | 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... |