#include "shoes.h"
using namespace std;
const int N=100005;
int a[2*N],G[2*N],f1[2*N],f2[2*N];
void Upd(int x,int dl) {
while (dl<=2*N) {
G[x]+=dl;
x+=(x & -x);
}
}
void Get(int x) {
int res=0;
while (0<dl) {
res+=G[x];
x-=(x & -x);
}
return res;
}
long long count_swaps(std::vector<int> s) {
long long ans=0;
for (int i=0; i<s.size(); i++) {
a[i+1]=s[i];
if (a[i+1]>0) f1[a[i+1]]=i+1;
if (a[i+1]<0) f2[-a[i+1]]=i+1;
Upd(i+1,1);
}
for (int i=1; i<=s.size()/2; i++) {
int l=1,r=2*(s.size()),mid,idx=-1;
while (l<=r) {
mid=(l+r)/2;
if (1<=Get(mid)) { idx=mid; r=mid-1; }
else l=mid+1;
}
if (a[idx]<0) {
int x=-a[idx];
ans+=Get(f1[x]-1)-1;
Upd(idx,-1);
Upd(f1[x],-1);
}
else {
int x=a[idx];
ans+=Get(f2[x]-1);
Upd(idx,-1);
Upd(f2[x],-1);
}
}
return ans;
}
Compilation message
shoes.cpp: In function 'void Get(int)':
shoes.cpp:15:11: error: 'dl' was not declared in this scope
while (0<dl) {
^~
shoes.cpp:19:9: error: return-statement with a value, in function returning 'void' [-fpermissive]
return res;
^~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:24:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<s.size(); i++) {
~^~~~~~~~~
shoes.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<=s.size()/2; i++) {
~^~~~~~~~~~~~
shoes.cpp:36:9: error: invalid operands of types 'int' and 'void' to binary 'operator<='
if (1<=Get(mid)) { idx=mid; r=mid-1; }
~^~~~~~~~~~
shoes.cpp:42:21: error: invalid operands of types 'void' and 'int' to binary 'operator-'
ans+=Get(f1[x]-1)-1;
~~~~~~~~~~~~^~
shoes.cpp:48:7: error: invalid operands of types 'long long int' and 'void' to binary 'operator+'
ans+=Get(f2[x]-1);
~~~^~~~~~~~~~~~~~
shoes.cpp:48:20: error: in evaluation of 'operator+=(long long int, void)'
ans+=Get(f2[x]-1);
^