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;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
int count_swaps(veci b) {
int n = sz(b) / 2;
veci a(2 * n + 1);
for(int i = 1; i <= 2 * n; ++i) a[i] = b[i - 1];
bool ch5 = 0;
for(int i = 1; i <= 2 * n; ++i) {
cin >> a[i];
if(i > n && -a[i - n] != a[i])
ch5 = 1;
if(i <= n && a[i] > 0)
ch5 = 1;
if(i > n && a[i] < 0)
ch5 = 1;
}
if(n == 1) return (a[1] > 0);
if(!ch5) return n * 1ll * (n - 1) / 2;
int ans = 0;
if(n <= 1000) {
for(int i = 1; i <= 2 * n; i += 2) {
if(a[i] > 0) {
for(int j = i + 1; j <= 2 * n; ++j) {
if(a[j] == -a[i]) {
for(int k = j; k > i; --k)
++ans, swap(a[k], a[k - 1]);
break;
}
}
} else {
for(int j = i + 1; j <= 2 * n; ++j) {
if(-a[j] == a[i]) {
for(int k = j; k > i + 1; --k)
++ans, swap(a[k], a[k - 1]);
break;
}
}
}
}
}
return ans;
}
# | 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... |