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 all(c) (c).begin(), (c).end()
#define rall(A) A.rbegin(),A.rend()
#define pb push_back
#define dbg(x) do {cerr << #x <<" = " << (x) << endl; } while (false)
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
//cout << setprecision(12) << fixed;
ll count_swaps(vector<int> s) {
ll ans = 0;
int n = s.size() >> 1;
vi L[n+1], R[n+1];
for(int i = 0; i < 2 * n; i++) {
cin >> s[i];
if(s[i] < 0)
L[-s[i]].pb(i+1);
else
R[s[i]].pb(i+1);
}
int a[2*n + 1];
bool vis[2 * n + 1];
memset(vis, 0, sizeof(vis));
int ind = 1;
for(int i = 2 * n - 1; i >= 0; i--) {
if(vis[i]) continue;
int l, r;
l = L[abs(s[i])].back();
r = R[abs(s[i])].back();
vis[l-1] = vis[r-1] = 1;
L[abs(s[i])].pop_back();
R[abs(s[i])].pop_back();
if(l > r) ans++;
a[l] = a[r] = ind;
ans += abs(r-l)-1;
ind++;
}
return ans;
}
// int main() {
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//
// return 0;
// }
//
# | 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... |