Submission #155990

#TimeUsernameProblemLanguageResultExecution timeMemory
155990GioChkhaidzeArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" using namespace std; const int N=200005; long long a[2*N],G[2*N],s[2*N],n; vector < long long > f1[2*N],f2[2*N]; void Upd(long long x,long long dl) { while (x<=2*N) { G[x]+=dl; x+=(x & -x); } } long long Get(long long x) { long long res=0; while (0<x) { res+=G[x]; x-=(x & -x); } return res; } long long count_swaps(std::vector<int> s) { long long ans=0; long long n=s.size(); for (int i=0; i<n; i++) { a[i+1]=s[i]; if (a[i+1]>0) f1[a[i+1]].push_back(i+1); if (a[i+1]<0) f2[-a[i+1]].push_back(i+1); Upd(i+1,1); } for (int i=0; i<n; i++) reverse(f1[i].begin(),f1[i].end()), reverse(f2[i].begin(),f2[i].end()); for (int i=1; i<=n/2; i++) { long long l=1,r=n,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) { long long x=-a[idx]; ans+=Get(f1[x].back()-1)-1; Upd(idx,-1); Upd(f1[x].back(),-1); f1[x].pop_back(); f2[x].pop_back(); } else { long long x=a[idx]; ans+=Get(f2[x].back()-1); Upd(idx,-1); Upd(f2[x].back(),-1); f1[x].pop_back(); f2[x].pop_back(); } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:35:3: error: 'reverse' was not declared in this scope
   reverse(f1[i].begin(),f1[i].end()),
   ^~~~~~~