# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932948 | velislavgarkov | Arranging Shoes (IOI19_shoes) | C++14 | 46 ms | 20824 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 <iostream>
#include <vector>
using namespace std;
const int MAXN=2e5+10;
vector <int> idx[MAXN][2];
int lef[MAXN], fen[MAXN];
bool sw[MAXN];
int n;
void update(int ind, int ch) {
if (ind==0) return;
while (ind<n) {
fen[ind]+=ch;
ind+=(ind & (-ind));
}
}
int query(int ind) {
if (ind==0) return 0;
int res=0;
while (ind>0) {
res+=fen[ind];
ind-=(ind & (-ind));
}
return res;
}
long long count_swaps(vector<int> s) {
n=s.size();
for (int i=0;i<n;i++) {
if (s[i]<0) idx[-s[i]][0].push_back(i);
else idx[s[i]][1].push_back(i);
lef[i]=-1;
sw[i]=false;
}
for (int i=0;i<n;i++) {
if (idx[i][0].empty()) continue;
for (int j=0;j<idx[i][0].size();j++) {
if (idx[i][0][j]<idx[i][1][j]) lef[idx[i][1][j]]=idx[i][0][j];
else {
lef[idx[i][0][j]]=idx[i][1][j];
sw[idx[i][0][j]]=true;
}
}
}
long long ans=0;
for (int i=1;i<n;i++) {
if (lef[i]==-1) update(i,1);
else {
long long s=query(i-1)-query(lef[i]);
s+=sw[i];
ans+=s;
update(lef[i],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... |