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 "shoes.h"
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
struct seggy {
int n;
vector<ll> t;
seggy(ll siz) {n = siz, t.resize(2*n);}
ll query(int l, int r) {
ll out = 0;
for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
if (l & 1)
out += t[l++];
if (r & 1)
out += t[--r];
}
return out;
}
void upd(int idx, int val) {
idx += n;
while (idx > 0)
t[idx] += val, idx /= 2;
}
};
ll count_inv(vector<ll> perm) {
seggy seg(perm.size());
ll out = 0;
for (int i = 0; i < perm.size(); i++) {
out += seg.query(perm[i], perm.size() - 1);
seg.upd(perm[i], 1);
}
return out;
}
long long count_swaps(std::vector<int> s) {
ll n = s.size();
vector<ll> neww(n);
int pnt = 1;
for (int i = 0; i < n; i++)
if (s[i] > 0)
neww[i] = pnt, pnt += 2;
pnt = 0;
for (int i = 0; i < n; i++)
if (s[i] < 0)
neww[i] = pnt, pnt += 2;
return count_inv(neww);
}
Compilation message (stderr)
shoes.cpp: In function 'll count_inv(std::vector<long long int>)':
shoes.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < perm.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... |