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>
#include "shoes.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
int cnt[maxn];
ll sum, sumabs;
void add(int pos, int x){
sum-= cnt[pos];
sumabs-= abs(cnt[pos]);
cnt[pos]+= x;
sum+= cnt[pos];
sumabs+= abs(cnt[pos]);
}
ll count_swaps(vector<int> a){
ll ans = 0;
int POS = 0;
for(int x : a){
if(x < 0){
add(cnt[-x], -1);
}
else{
add(cnt[x], 1);
}
ll df = sumabs;
ans+= sumabs;
if(sum & 1){
if(sum == sumabs)
ans++, df++;
else
ans--, df--;
}
cout << POS << " " << df << endl;
POS++;
}
return ans / 2;
}
# | 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... |