# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159127 | kig9981 | Arranging Shoes (IOI19_shoes) | C++17 | 110 ms | 16628 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> L[100001], R[100001];
int tree[200001];
void update(int n, int v)
{
for(++n;n<=200000;n+=n&-n) tree[n]+=v;
}
int get_cnt(int n)
{
int ret=0;
for(++n;n;n-=n&-n) ret+=tree[n];
return ret;
}
long long count_swaps(vector<int> S)
{
int N=S.size();
priority_queue<tuple<int,int,int>> Q;
long long ret=0;
for(int i=N-1;i>=0;i--) {
if(S[i]>0) R[S[i]].push_back(i);
else L[-S[i]].push_back(i);
update(i,1);
}
for(int i=N/2;i;i--) for(int j=0;j<L[i].size();j++) Q.emplace(-L[i][j]-R[i][j],L[i][j],R[i][j]);
while(!Q.empty()) {
auto[s,i,j]=Q.top();
Q.pop();
update(i,-1);
ret+=get_cnt(i);
update(j,-1);
ret+=get_cnt(j);
}
return ret;
}
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... |