# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
980597 | TitanicXDzz | Arranging Shoes (IOI19_shoes) | C++14 | 49 ms | 16832 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;
vector<int> v[200010];
int co[200010];
int dp[200010];
int visited[200010];
int n;
void update(int idx,long long val){
while(idx<=n){
dp[idx]+=val;
idx+=(idx & -idx);
}
}
long long read(long long idx){
long long sumi=0;
while(idx>=1){
sumi+=dp[idx];
idx-=(idx& -idx);
}
return sumi;
}
long long count_swaps(vector<int> s) {
long long ans=0;
for(auto x:s){
n++;
if(s[n-1]<0)
s[n-1]=100000-s[n-1];
v[s[n-1]].push_back(n);
}
for(int i=1;i<=n;i++){
update(i,1);
}
for(int i=1;i<=n;i++){
if(visited[i]==1)
continue;
long long x=s[i-1];
if(x>=100001)
x-=100000;
else
x+=100000;
int j=v[x][co[x]];
visited[i]=1;
visited[j]=1;
co[x]++;
co[s[i-1]]++;
ans+=read(j)-1;
update(i,-1);
update(j,-1);
if(x<s[i-1]){
ans-=1;
}
}
return ans;
}
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... |