이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=2e5+99;
int n,a[N],L[N],R[N],fen[N];
ll ans;
vector<int> A[N],B[N];
void add(int x,int val){
for(x++;x>0;x-=(x&-x)){
fen[x]+=val;
}
}
int get(int x){
int res=0;
for(x++;x<N;x+=(x&-x)){
res+=fen[x];
}
return res;
}
ll count_swaps(vector<int> D) {
n=D.size()/2;
f(i,0,2*n){
a[i]=D[i];
if(a[i]>0) A[a[i]].pb(i);
else B[-a[i]].pb(i);
}
int cnt=0;
f(i,1,n+1){
f(j,0,int(A[i].size())){
L[cnt]=B[i][j],R[cnt]=A[i][j];
if(R[cnt]<L[cnt]){
ans++;
swap(L[cnt],R[cnt]);
}
cnt++;
}
}
vector<int> vec(n);
iota(all(vec),0);
sort(all(vec),[&](int u,int v){ return L[u]<L[v]; });
//dbgv(vec);
f(i,0,n){
ans+=get(L[vec[i]])+get(R[vec[i]]);
add(R[vec[i]],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... |