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 = 2e5 + 10;
map<int, vector<int> > mp;
bool mark[maxn];
int fn[maxn];
void add(int pos, int x){
for(pos+= 3; pos < maxn; pos+= pos & -pos)
fn[pos]+= x;
}
int ask(int pos){
int ans = 0;
for(pos+= 3; pos > 0; pos-= pos & -pos)
ans+= fn[pos];
return ans;
}
ll count_swaps(vector<int> a){
for(int i = sz(a)-1; i >= 0; i--){
mp[a[i]].PB(i);
}
for(int i = 0; i < sz(a); i++){
add(i, 1);
}
ll ans = 0;
for(int i = 0; i < sz(a); i++){
if(mark[i])
continue;
mp[a[i]].pop_back();
int pos = mp[-a[i]].back();
mp[-a[i]].pop_back();
ans+= a[i] > 0;
ans+= ask(pos) - ask(i) - 1;
mark[i] = 1;
mark[pos] = 1;
add(i, -1);
add(pos, -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... |