This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (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... |