이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
int 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... |