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>
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define sz(x) (int)(x.size())
#define fi first
#define se second
template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef pair<int,int> ii;
const int MX = (int)(1e5+5);
int n,N;
vector<int> vec[2*MX];
ll count_swaps(vector<int> s) {
n=sz(s);
N=n/2;
ordered_set <ii> X;
ll ans=0;
for (int i = n-1; i >= 0; i--)
{
X.insert({i,s[i]});
if(s[i]>0)vec[s[i]].push_back(i);
else vec[-s[i]+N].push_back(i);
}
while(!X.empty()){
ii f=(*X.begin()),m;
if(f.se<0){
vec[-f.se+N].pop_back();
m={vec[-f.se].back(),-f.se};
vec[-f.se].pop_back();
}
else{
vec[f.se].pop_back();
m={vec[f.se+N].back(),-f.se};
vec[f.se+N].pop_back();
}
ans+=X.order_of_key(m)-1+(f.se>0);
X.erase(X.begin()),X.erase(m);
}
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... |