# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
419100 | FlippenFaz | Arranging Shoes (IOI19_shoes) | C++14 | 813 ms | 163616 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long ll;
#define SIZE 524288
map<ll, queue<int>> shoesList;
vector<ll> offset;
vector<ll> decSet;
void incOff(int pos) {
pos+=SIZE;
while (pos > 0) {
offset[pos]++;
pos/=2;
}
}
void decOff(int pos) {
pos+=SIZE;
while (pos > 0) {
decSet[pos]++;
offset[pos]--;
pos/=2;
}
}
ll getDec(int pos) {
ll sum = 0;
int left = SIZE;
int right = pos + SIZE;
while (left <= right) {
if (left%2 == 1) {sum+=decSet[left++];}
if (right%2 == 0) {sum+=decSet[right--];}
left/=2;
right/=2;
}
return sum;
}
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(SIZE*2);
decSet.resize(SIZE*2);
//cerr << "OFFSET: " << offset[0] << " " << offset[100] << endl << endl;
for (ll i = 0; i < s.size(); i++) {
ll pos = i;
//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 {
ll prev = -1;
ll curPos = shoesList[-s[i]].front();
//cerr << "GET OFF CUR: " << getOff(curPos) << "GET OFF PREV: " << getOff(prev) << endl;
if ((getOff(curPos) - getOff(prev)) > 0) {
ll temp = curPos;
curPos = curPos + getOff(curPos) - getOff(prev);
prev = temp;
//cerr << endl;
//cerr << "CURPOS: " << curPos << endl;
while ( (getOff(curPos) - getOff(prev) + getDec(curPos) - getDec(prev)) > 0) {
ll temp = curPos;
curPos = curPos + getOff(curPos) - getOff(prev) + getDec(curPos) - getDec(prev);
prev = temp;
//cout << "UPDATED POS: " << curPos << endl;
//cerr << "GET OFF CUR: " << getOff(curPos) << "GET OFF PREV: " << getOff(prev) << endl;
//cout << "OVERLAPS: " << getDec(curPos) << " - " << getDec(prev) << endl;
}
}
//cerr << endl;
//cerr << "ACTUAL INVPOS: " << curPos << endl;
if (s[i] > 0) {
curPos++;
}
//cerr << "ADDING: " << (i - curPos) << endl;
sum += (i - curPos);
//cerr << "INCREMENTING: " << curPos << endl;
incOff(curPos);
//cerr << "Decrementing: " << i+1 << endl;
decOff(i+1);
shoesList[-s[i]].pop();
}
}
return sum;
}
컴파일 시 표준 에러 (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... |