이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "shoes.h"
using ll = long long;
struct Seg {
int i, j;
int s = 0;
Seg *l, *r;
Seg(int i, int j): i(i), j(j) {
if (j - i == 1) {
l = r = nullptr;
} else {
int k = i + j >> 1;
l = new Seg(i, k);
r = new Seg(k, j);
}
}
int inc(int I) {
if (i <= I and I < j) {
s++;
if (l) l->inc(I), r->inc(I);
}
}
int sum(int I) {
return j <= I ? s : I <= i ? 0 : l->sum(I) + r->sum(I);
}
};
ll count_swaps(vector<int> _seq) {
vector<int> found(_seq.size() * 2 + 5);
vector<ll> seq;
for (int v : _seq) seq.push_back(ll(v) * _seq.size() + ((v > 0) - (v < 0)) * found[v + _seq.size()]++);
unordered_map<ll,int> pos; pos.max_load_factor(0.5);
for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i;
sort(seq.rbegin(), seq.rend(), [&](ll i, ll j) {
int d = min(pos[i], pos[-i]) - min(pos[j], pos[-j]);
return d ? d < 0 : i < j;
});
for (ll& v : seq) v = pos[v];
ll ans = 0;
Seg s(0, seq.size());
for (ll v : seq) ans += s.sum(v), s.inc(v);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In constructor 'Seg::Seg(int, int)':
shoes.cpp:14:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | int k = i + j >> 1;
| ~~^~~
shoes.cpp: In member function 'int Seg::inc(int)':
shoes.cpp:24:5: warning: no return statement in function returning non-void [-Wreturn-type]
24 | }
| ^
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i;
| ~~^~~~~~~~~~~~
# | 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... |