# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
607608 | nyaruhodo | Arranging Shoes (IOI19_shoes) | C++14 | 1 ms | 284 KiB |
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>
using namespace std;
typedef long long ll;
long long count_swaps(std::vector<int> s) {
set<pair<ll,ll>> st; // val, pos
ll cnt=0;
vector<ll> vis(s.size(),0);
for(ll i = 0;i < s.size();i++){
if(s[i] > 0){
auto lb = st.lower_bound({-s[i],-1});
if(lb!=st.end() && lb->first==-s[i]){
auto p = *lb;
st.erase(lb);
cnt+=i-p.second-1;
if(s[i]<0) cnt++;
vis[i]=1,vis[p.second]=1;
}
}else
st.insert({s[i],i});
}
st.clear();
for(ll i = 0;i < s.size();i++){
if(vis[i]) continue;
auto lb = st.lower_bound({-s[i],-1});
if(lb == st.end() || lb->first!=-s[i]){
st.insert({s[i],i});
continue;
}
auto p = *lb;
st.erase(lb);
cnt+=i-p.second-1;
if(s[i]<0) cnt++;
}
return cnt;
}
Compilation message (stderr)
# | 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... |