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>
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
using namespace std;
//#define int long long
#define ll long long
#define xx first
#define yy second
#define all (x) begin(x), end(x)
#define cin fin
#define cout fout
ll count_swaps(vector <int> s){
int n = int (s.size());
unordered_map <int, queue<int>> frec;
vector <int> bit(n + 1);
ll cnt = 0;
for (int i = 0; i < n; ++ i)
{
int poz;
if (frec[-s[i]].empty()){
poz = i + 1;
frec[s[i]].push(poz);
}
else{
poz = frec[-s[i]].front();
frec[-s[i]].pop();
cnt += i;
for (int ans = poz; ans; ans -= ans & (-ans))
cnt -= bit[ans];
if (s[i] < 0)
cnt ++;
}
for (int ans = poz; ans <= n; ans += ans & (-ans))
bit[ans] ++;
}
return cnt;
}
# | 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... |