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>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ordered_set ord;
set<int>st[400005];
int n,a[400005],fix[400005],ind,k,f;
vector<int>gg;
int d(int x){
return ord.order_of_key(x);
}
ll count_swaps(vector<int>v){
ll ans = 0;
int n = (int)v.size();
for(int i=1; i<=n; i++){
a[i] = v[i - 1];
st[a[i] + n].insert(i);
}
for(int i=1; i<=n; i++){
if(fix[i])continue;
if(a[i] > 0)ans++;
st[a[i] + n].erase(st[a[i] + n].find(i));
ind = (*st[-a[i] + n].begin());
fix[ind] = 1;
st[-a[i] + n].erase(st[-a[i] + n].begin());
k = (int)ord.size() - d(i);
f = (int)ord.size() - d(ind);
ans += (ind + f) - (i + k) - 1;
ord.insert(ind);
}
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... |