# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143939 | tincamatei | Arranging Shoes (IOI19_shoes) | C++14 | 111 ms | 14844 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 <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;
vector<int> aib;
static inline int lsb(int x) {
return x & (-x);
}
void update(int poz, int val) {
while(poz <= aib.size()) {
aib[poz] += val;
poz += lsb(poz);
}
}
int query(int poz) {
int rez = 0;
while(poz > 0) {
rez += aib[poz];
poz -= lsb(poz);
}
return rez;
}
long long sweep(const vector<int> &x) {
int N = x.size() / 2;
long long rez = 0LL;
vector<int> last(1 + N, -1);
for(int i = 0; i < 2 * N; ++i) {
if(last[abs(x[i])] == -1)
last[abs(x[i])] = i + 1;
else {
rez = rez + query(i) - query(last[abs(x[i])]);
update(i + 1, 1);
update(last[abs(x[i])], 1);
if(x[i] < 0)
++rez;
}
}
return rez;
}
long long count_swaps(std::vector<int> s) {
int N = s.size() / 2;
vector<vector<int> > pozLeft(N), pozRight(N);
vector<int> norm(2 * N);
for(int i = 0; i < 2 * N; ++i)
if(s[i] < 0)
pozLeft[-s[i] - 1].push_back(i);
else
pozRight[s[i] - 1].push_back(i);
int id = 0;
for(int i = 0; i < N; ++i) {
for(int j = 0; j < pozLeft[i].size(); ++j) {
++id;
norm[pozLeft[i][j]] = -id;
norm[pozRight[i][j]] = id;
}
}
aib.clear();
aib.resize(1 + 2 * N, 0);
return sweep(norm);
}
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... |