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"
#define sz(x) (int)x.size()
#define mkt make_tuple
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define mk make_pair
#define pii pair<int,int>
#define debug printf
#define all(x) x.begin(),x.end()
const int MAXN = 1e5+10 ;
using namespace std ;
int freq[MAXN][2] ;
/*
6
-2 2 -2 2 -2 2
*/
long long count_swaps(vector<int> v)
{
ll ans = 0LL ;
for(int i = 0 ; i < sz(v) ; i++ )
{
//debug("%d %d\n" , freq[ abs(v[i]) ][0] , freq[ abs(v[i]) ][1] ) ;
if( v[i] < 0 )
{
if( freq[ -v[i] ][1] > 0 ) freq[ -v[i] ][1] -- , ans += (ll)i ;
else freq[ -v[i] ][0]++ , ans -= (ll)i , ans-- ;
}
else
{
if( freq[ v[i] ][0] > 0) freq[ v[i] ][0]-- , ans += (ll)i ;
else freq[v[i]][1]++ , ans -= (ll)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... |