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>
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
const string fileio = "";
constexpr int tests = 1, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;
long long count_swaps(std::vector<int> s) {
int n = s.size();
vector<int> pr(2*n,-1);
for (int i = 0; i < n+n; i++) {
if (s[i] > 0) continue;
for (int j = 0; j < n+n; j++) {
if (i == j) continue;
if (~pr[j]) continue;
if (-s[j] == s[i]) {
pr[j] = i;
pr[i] = j;
break;
}
}
}
ll res = 0;
for (int i = 0; i < n; i++) {
if (s[i] > 0) continue;
int a = i, b = pr[i];
if (a > b) swap(a, b),res++;
for (int j = a+1; j <= b-1; j++)
if (pr[j] <= b)
res++;
}
return res;
}
# | 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... |