제출 #418903

#제출 시각아이디문제언어결과실행 시간메모리
418903FlippenFazArranging Shoes (IOI19_shoes)C++14
10 / 100
1087 ms57700 KiB
#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; } } 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; sum += (i - curPos); cerr << "INCREMENTING: " << curPos << endl; incOff(curPos); shoesList[-s[i]].pop(); } } return sum; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:45:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (ll i = 0; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...