# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1274229 | gazizmadi11 | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#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
using namespace std;
const int N=2e5+7;
const int mod=998244353;
const int inf=2e9;
int count_swaps(vector<int>S){
vector<int>a[S.size()+1];
vector<int>b[S.size()+1];
int 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{
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;
// }