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>
using namespace std;
vector<int> P[100001];
int tree[200001];
void update(int n, int v)
{
for(++n;n<=200000;n+=n&-n) tree[n]+=v;
}
int get_cnt(int n)
{
int ret=0;
for(++n;n;n-=n&-n) ret+=tree[n];
return ret;
}
long long count_swaps(vector<int> S)
{
int N=S.size();
long long ret=0;
for(int i=N-1;i>=0;i--) {
if(S[i]>0) P[S[i]].push_back(i);
update(i,1);
}
for(int i=0;i<N;i++) if(S[i]<0) {
update(i,-1);
ret+=get_cnt(i);
update(P[-S[i]].back(),-1);
ret+=get_cnt(P[-S[i]].back());
P[-S[i]].pop_back();
}
return ret;
}
# | 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... |