이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define sp " "
#define debug(x) cout << #x << " => " << x << "\n"
const int mod = 1e9 + 7;
const ld err = 1e-6;
int n, arr[200005];
vector <int> pos[200005];
bool vis[200005];
ll ans;
struct fenwick_tree{
int bit[200005];
void upd(int idx, int val){
for(; idx <= n; idx += (idx & -idx)){
bit[idx] += val;
}
}
int query(int idx){
int res = 0;
for(; idx >= 1; idx -= (idx & -idx)){
res += bit[idx];
}
return res;
}
int query(int l, int r){
return query(r) - query(l - 1);
}
} fwt;
long long count_swaps(vector<int> s) {
n = s.size() / 2;
for(int i = 1; i <= 2 * n; i++)
arr[i] = s[i - 1];
for(int i = 2 * n; i >= 1; i--){
pos[arr[i] + n].pb(i);
}
for(int i = 1, u, v; i <= 2 * n; i++){
if(vis[i]) continue;
u = i;
v = pos[arr[i] * (-1) + n].back();
vis[u] = vis[v] = 1;
pos[arr[i] + n].pop_back();
pos[arr[i] * (-1) + n].pop_back();
if(arr[i] < 0){
ans += (v - u - 1) - fwt.query(u, n) + fwt.query(v, n);
}
else{
ans += (v - u) - fwt.query(u, n) + fwt.query(v, n);
}
fwt.upd(v, 1);
}
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... |