# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312204 | tjdgus4384 | Arranging Shoes (IOI19_shoes) | C++14 | 251 ms | 141200 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<bits/stdc++.h>
using namespace std;
deque<int> vp[100001], vm[100001], v, v2;
long long merge_sort(int x, int y){
if(x == y) return 0;
int mid = (x+y)/2;
long long ret = merge_sort(x, mid) + merge_sort(mid+1, y);
int f = x, s = mid+1;
vector<int> newv;
while(f <= mid && s <= y){
if(v2[f] <= v2[s]){
newv.push_back(v2[f]);
f++;
}
else {
newv.push_back(v2[s]);
ret += mid - f + 1;
s++;
}
}
for(int i = f;i <= mid;i++) newv.push_back(v2[i]);
for(int i = s;i <= y;i++) newv.push_back(v2[i]);
for(int i = x;i <= y;i++) v2[i] = newv[i - x];
return ret;
}
long long count_swaps(vector<int> S){
for(int i = 0;i < S.size();i++){
if(S[i] < 0){
if(vp[-S[i]].empty()) vm[-S[i]].push_back(i);
else{
v.push_back(i);
v.push_back(vp[-S[i]].front());
vp[-S[i]].pop_front();
}
}
if(S[i] > 0){
if(vm[S[i]].empty()) vp[S[i]].push_back(i);
else{
v.push_back(vm[S[i]].front());
v.push_back(i);
vm[S[i]].pop_front();
}
}
}
for(int i = 0;i < v.size();i++) v2.push_back(v[i]);
return merge_sort(0, v2.size()-1);
}
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... |