# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
418914 | FlippenFaz | Arranging Shoes (IOI19_shoes) | C++14 | 2 ms | 2272 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>
#include "shoes.h"
using namespace std;
typedef long long ll;
#define SIZE 131072
map<int, queue<int>> shoesList;
vector<ll> offset;
void incOff(int pos) {
pos+=SIZE;
while (pos > 0) {
offset[pos]++;
pos/=2;
}
}
void decOff(int pos) {
pos+=SIZE;
while (pos > 0) {
offset[pos]--;
pos/=2;
}
}
ll getOff(int pos) {
if(pos == -1) {
return 0;
}
ll sum = 0;
int left = SIZE;
int right = pos + SIZE;
while (left <= right) {
if (left%2 == 1) {sum+=offset[left++];}
if (right%2 == 0) {sum+=offset[right--];}
left/=2;
right/=2;
}
return sum;
}
ll count_swaps(vector<int> s) {
ll sum = 0;
offset.resize(262144);
cerr << "OFFSET: " << offset[0] << " " << offset[100] << endl << endl;
for (ll i = 0; i < s.size(); i++) {
ll pos = 0;
if (s[i] > 0) {pos = i;}
else {pos = i+1;}
cerr << endl;
cerr << "I: " << i << " SHOE: " << s[i] << endl;
cerr << "SIZE: " << shoesList[-s[i]].size() << "POS OF INVERSE:" << shoesList[-s[i]].front() << endl;
cerr << "CUROFFSET 0: " << offset[SIZE] << "TOTAL: " << offset[1] << endl;
if (shoesList[-s[i]].size() == 0) {
shoesList[s[i]].push(pos);
} else {
int prev = -1;
int curPos = shoesList[-s[i]].front();
cerr << "GET OFF CUR: " << getOff(curPos) << "GET OFF PREV: " << getOff(prev) << endl;
while ( (getOff(curPos) - getOff(prev)) > 0) {
int temp = curPos;
curPos = curPos + getOff(curPos) - getOff(prev);
prev = temp;
}
cerr << endl;
cerr << "ACTUAL INVPOS: " << curPos << endl;
cerr << "ADDING: " << (i - curPos) << endl;
sum += (i - curPos);
cerr << "INCREMENTING: " << curPos << endl;
incOff(curPos);
decOff(i);
shoesList[-s[i]].pop();
}
}
return sum;
}
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... |