# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
855809 | Huseyn123 | Arranging Shoes (IOI19_shoes) | C++17 | 67 ms | 21376 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>
#define MAX 200001
#include "shoes.h"
using namespace std;
typedef long long ll;
ll sum[MAX],cnt=1;
void update(ll x,ll v){
while(x<=cnt){
sum[x]+=v;
x+=x&-x;
}
}
ll query(ll x){
ll res=0;
while(x>=1){
res+=sum[x];
x-=x&-x;
}
return res;
}
ll count_swaps(vector<int> s) {
int n=s.size();
cnt=n;
ll res=0;
vector<vector<int>> c;
vector<vector<int>> d;
c.resize(n+1);
d.resize(n+1);
int ind=1;
for(auto x:s){
if(x<0){
c[-x].push_back(ind);
}
else{
d[x].push_back(ind);
}
ind++;
}
vector<pair<int,int>> e;
for(int i=1;i<=n;i++){
for(int j=0;j<c[i].size();j++){
int h1,h2;
h1=c[i][j];
h2=d[i][j];
if(h1<h2){
e.push_back(make_pair(h1,h2));
}
else{
e.push_back(make_pair(h2,h1));
res++;
}
}
}
sort(e.begin(),e.end());
for(auto x:e){
update(x.first,-1);
update(x.second,-1);
res+=query(x.second)-query(x.first-1)+x.second-x.first+1;
}
return res;
}
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... |