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 "shoes.h"
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end();
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
vector<int> V[N];
vector<int> pos[N], neg[N];
int v[N];
int fen[N];
void Add(int idx){
idx ++;
for(; idx < N; idx += (idx & -idx))
fen[idx] ++;
}
int Get(int idx){
idx ++;
int res = 0;
for(; idx; idx -= idx & (-idx))
res += fen[idx];
return res;
}
ll count_swaps(vector<int> s) {
int n = s.size() >> 1;
for(int i = 0; i < n + n; i++){
if(s[i] > 0)
pos[abs(s[i])].pb(i);
else
neg[abs(s[i])].pb(i);
}
ll res = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < (int) pos[i].size(); j++){
v[pos[i][j]] = v[neg[i][j]] = min(pos[i][j], neg[i][j]);
if(v[pos[i][j]] == pos[i][j])
res ++;
}
}
for(int i = n + n - 1; i >= 0; i--){
res += Get(v[i] - 1);
Add(v[i]);
}
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... |