# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1268832 | FaresSTH | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
#define S second
#define F first
ll count_swaps(vector<int>a){
ll res=0;
set<int>p[2];
int n=a.size();
for(int i=0;i<n;i++){
if(a[i]<0)p[0].insert(i);
else p[1].insert(i);
}
for(int i=0;i<n;i++){
auto *it=p[i%2].lower_bound(i);
p[i%2].erase(it);
p[i%2].insert(i);
p[1-i%2].insert(it);
p[1-i%2].erase(i);
res+=it-i;
}
return res;
}
// MalekLoky 3mk