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;
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int sz = 100005;
ll BIT[sz];
void add(ll x, ll delta){
for(; x < sz; x += x & -x)
BIT[x] += delta;
}
ll sum(ll x){
ll res = 0;
for(; x > 0; x -= x & -x)
res += BIT[x];
return res;
}
ll count_swaps(vi s){
map<int, deque<int>> m;
int n = s.size();
vector<bool> marked(n+5);
for(int i = 0; i < n; i++)
m[s[i]].pb(i);
ll ans = 0;
for(int i = 0; i < n; i++){
if(marked[i])
continue;
int ind = m[-s[i]].front();
m[-s[i]].pop_front();
m[s[i]].pop_front();
marked[i] = marked[ind] = 1;
//cerr << s[i] << ' ' << i << ' ' << ind << ' ' << sum(ind) << '\n';
ans += ind - (sum(ind) - sum(i)) - i;
if(s[i] < 0)
ans--;
add(ind+1, 1);
//cout << ans << '\n';
}
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... |