Submission #549957

#TimeUsernameProblemLanguageResultExecution timeMemory
549957CyberSleeperArranging Shoes (IOI19_shoes)C++14
100 / 100
186 ms139596 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; int F[200007], sz, N; void upd(int i, int x){ i++; for(; i<=sz; i+=(i&-i)) F[i]+=x; } int pre(int i){ i++; int ret=0; for(; i>0; i-=(i&-i)) ret+=F[i]; return ret; } long long count_swaps(std::vector<int> s) { ll ret=0; sz=s.size(), N=sz/2; queue<int> cnt[sz+1]; bool udh[sz]; for(int i=0; i<sz; i++){ s[i]+=N; cnt[s[i]].push(i); upd(i, 1); } memset(udh, 0, sizeof(udh)); for(int i=0, j; i<sz; i++){ if(udh[i]) continue; j=cnt[N-s[i]+N].front(); cnt[N-s[i]+N].pop(); cnt[s[i]].pop(); udh[i]=1, udh[j]=1; ret+=pre(j-1); if(s[i]<N) ret--; upd(i, -1); upd(j, -1); //cout << i << ' ' << ret << endl; } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...