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 <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long ll;
ll count_swaps(vector<int> s) {
set<pair<int, int>> L, R;
int n = s.size();
// for(int i = 0; i < n; i ++){
// if(s[i] < 0)
// L.insert({-s[i], i});
// else
// R.insert({s[i], i});
// }
ll result = 0;
for(int i = 0; i < n; i += 2){
int j = i + 1;
while(s[j] != -s[i])
++ j;
while(j - 1 > i)
swap(s[j], s[j - 1]),
++ result, -- j;
if(s[i] > 0)
swap(s[j], s[i]), ++ result;
// cout << result << endl;
// if(!L.count({-s[i], i}) && !R.count({s[i], i}))
// continue;
// if(s[i] < 0){
// L.erase({-s[i], i});
// auto it = R.lower_bound({-s[i], -1});
// assert(it != R.end());
// result += abs(it->second - (i + 1));
// R.erase(it);
// }else{
// R.erase({s[i], i});
// auto it = L.lower_bound({s[i], -1});
// assert(it != L.end());
// result += 1 + abs(it->second - i);
// L.erase(it);
// }
}
cout << result << endl;
return result;
}
# | 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... |