이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
const int MAXN=200000+100;
int fen[MAXN];
int querry(int j){
if (j==0){
return 0;
}
return fen[j]+querry(j-(j&-j));
}
long long count_swaps(vector<int> a){
return 0;
int n=a.size();
int f=0;
long long rez=0;
vector<int> v1[MAXN],v2[MAXN];
for (int i=0;i<n;++i){
int curr=a[i];
if (curr>0){
v1[curr].push_back(i);
if (!v2[curr].empty()){
int x=*--v2[curr].end();
v2[curr].pop_back();
v1[curr].pop_back();
rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f);
for (int j=i+1;j<=MAXN;j+=j&-j){
++fen[j];
}
for (int j=x+1;j<=MAXN;j+=j&-j){
++fen[j];
}
++f;
}
}
else {
curr*=-1;
v2[curr].push_back(i);
if (!v1[curr].empty()){
int x=*--v1[curr].end();
v2[curr].pop_back();
v1[curr].pop_back();
rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f)-1;
for (int j=i+1;j<=MAXN;j+=j&-j){
++fen[j];
}
for (int j=x+1;j<=MAXN;j+=j&-j){
++fen[j];
}
++f;
}
}
}
return rez;
}
# | 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... |