#include <bits/stdc++.h>
#include "shoes.h"
#define pb push_back
// #define pf push_front
// #define F first
// #define S second
// #define all(v) v.begin(),v.end()
// #define pii pair<int,int>
// #define tm (tl+tr)/2
// #define TL v+v, tl, tm
// #define TR v+v+1, tm+1, tr
// #define DA l <= tl && tr <= r
// #define NE r < tl || tr < l
// #define double long double
// #define int long long s
using namespace std;
// const int N=2e5+7;
// const int mod=998244353;
// const int inf=2e9;
long long count_swaps(vector<int>S){
vector<int>a[S.size()+1];
vector<int>b[S.size()+1];
long long ans=0;
for(int i=0; i < S.size(); i++){
int x = S[i];
if(x > 0){
if(a[x].size()){
ans+=i-a[x].back()-1;
a[x].pop_back();
}
else b[x].pb(i);
}
else{
x=abs(x);
if(b[x].size()){
ans+=i-b[x].back();
b[x].pop_back();
}
else a[x].pb(i);
}
}
return ans;
}
// void solve(){
// }
// signed main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// int dioz=1;
// cin >> dioz;
// while(dioz--)solve();
// return 0;
// }
# | 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... |