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>
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 262144
#define pa pair<ll, ll>
#define ld long double
queue<ll> poi[mn][2];
ll t[2 * mn];
void upd(ll l, ll r, ll val=1){
for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){
if(l&1) t[l++]+=val;
if(r&1) t[--r]+=val;
}
}
ll get(ll pos){
ll ret=0;
for(pos+=mn;pos>0;pos>>=1) ret+=t[pos];
return ret;
}
long long int count_swaps(vc<int> a){
ll n=a.size()/2;
ll ans=0;
loop(i, 0, 2* n){
ll t=a[i];
if(poi[abs(t)][t<0].size()){
ll match=poi[abs(t)][t<0].front();poi[abs(t)][t<0].pop();
ans+=i-get(match)-match;
if(t>0) ans--;
upd(match, i);
}
else poi[abs(t)][t>0].push(i);
}
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... |