이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <map>
#include <vector>
#include <algorithm>
#include <set>
int abs(int a)
{
return (a < 0)?-a:a;
}
long long count_swaps(std::vector<int> s) {
int i, sz, norp;
long long cnt = 0;
std::map<int, std::vector<int> > pos[2];
for (i = 0; i < s.size(); i++)
{
sz = abs(s[i]);
norp = (s[i] > 0);
if (pos[norp].find(sz) == pos[norp].end())
pos[norp][sz] = std::vector<int>();
pos[norp][sz].push_back(i);
}
int nxt;
std::vector<int> moved;
int ismoved[200005] = {0};
for (i = 0; i < s.size(); i++)
{
sz = abs(s[i]);
norp = (s[i] > 0);
if (ismoved[i])
continue;
// printf("%d ", sz);
nxt = std::upper_bound(pos[!norp][sz].begin(), pos[!norp][sz].end(), i) - pos[!norp][sz].begin();
if (nxt == pos[!norp][sz].size())
continue;
while ((long long) ismoved[pos[!norp][sz][nxt]])
nxt++;
// printf("%d ", pos[sz][nxt]);
cnt += (pos[!norp][sz][nxt] - i - 1) - (std::upper_bound(moved.begin(), moved.end(), pos[!norp][sz][nxt]) - std::upper_bound(moved.begin(), moved.end(), i));
// printf("%d ", (s[i] > 0));
cnt += (s[i] > 0);
moved.insert(std::upper_bound(moved.begin(), moved.end(), pos[!norp][sz][nxt]), pos[!norp][sz][nxt]);
ismoved[pos[!norp][sz][nxt]] = 1;
// printf("%lld\n", cnt);
}
return cnt;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < s.size(); i++)
~~^~~~~~~~~~
shoes.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < s.size(); i++)
~~^~~~~~~~~~
shoes.cpp:35:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (nxt == pos[!norp][sz].size())
~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |