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>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
long long count_swaps(vector<int> s) {
int n = (int) s.size();
long long ans = 0;
{
vector<vector<int>> cnt(2 * n + 1);
for (int i = 0; i < n; i++) {
cnt[s[i] + n].emplace_back(i);
}
int c = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (int) cnt[n + i].size(); j++) {
s[cnt[n + i][j]] = c;
s[cnt[n - i][j]] = c;
if (cnt[n + i][j] < cnt[n - i][j]) {
ans++;
}
c++;
}
}
}
debug(ans, s);
return ans;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << count_swaps({2, 1, -1, -2}) << '\n';
cout << count_swaps({-2, 2, 2, -2, -2, 2}) << '\n';
cout << count_swaps({-1, 2, 1, 1, -2, -1}) << '\n';
return 0;
}
#endif
# | 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... |