이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp(x...) array<int, 2>({x})
#define pb push_back
#define int int64_t
#define vi vector<int32_t>
using namespace std;
#include "shoes.h"
constexpr static int MXSIZE = 1e6;
struct Fenwick
{
int v[MXSIZE];
void set(int i, int val) { for (++i;i<MXSIZE;i+=i&(-i)) v[i] += val; }
int get(int i) { int res = 0; for(++i;i>0;i-=i&(-i)) res += v[i]; return res; }
int get(int l, int r) { return get(r) - get(l); }
};
int subtask1(vi& s)
{
if (s[0] > 0)
return 1;
else
return 0;
}
Fenwick fw;
int last[2][MXSIZE];
bitset<MXSIZE> paired;
map<array<int, 2>, int> p;
long long count_swaps(vi s)
{
for (int i = 0; i < s.size(); i++)
{
int j = s[i] > 0 ? 1 : 0;
array<int, 2> q = {s[i], last[j][abs(s[i])]};
p[q] = i;
last[j][abs(s[i])]++;
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < MXSIZE; j++)
last[i][j] = 0;
int res = 0;
for (int i = 0; i < s.size(); i++)
{
int j = s[i] > 0 ? 1 : 0;
array<int, 2> q = {-s[i], last[j][abs(s[i])]};
last[j][abs(s[i])]++;
if (paired[i])
continue;
int ps = p[q];
paired[ps] = true;
res += ps - i - 1 - fw.get(i, ps);
if (s[i] > 0)
res++;
fw.set(ps, 1);
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
shoes.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < s.size(); 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... |