제출 #240828

#제출 시각아이디문제언어결과실행 시간메모리
240828zoomswkArranging Shoes (IOI19_shoes)C++17
10 / 100
203 ms269688 KiB
#include "shoes.h" #include <queue> using namespace std; int n; int done[200005]; queue<int> occ[400005]; int t[400005]; int tmp[200005]; int qr(int l, int r){ int res = 0; for(int i=l; i<r; i++) res += tmp[i]; /* for(l+=n, r+=n; l<r; l>>=1, r>>=1){ if(l&1) res += t[l++]; if(r&1) res += t[--r]; } */ return res; } void add(int pos){ tmp[pos]++; for(t[pos+=n]++; pos>1; pos>>=1) t[pos>>1] = t[pos]+t[pos^1]; } long long count_swaps(std::vector<int> s) { n = (int)s.size(); for(int i=0; i<n; i++) occ[s[i]+n/2].push(i); long long res = 0; for(int i=0, pairs_done=0; i<n; i++){ if(done[i]) continue; occ[s[i]+n/2].pop(); int pos = occ[-s[i]+n/2].front(); occ[-s[i]+n/2].pop(); res += pos-2*pairs_done+qr(i, n); if(s[i] < 0) res--; add(pos); done[pos]++; pairs_done++; } return res; }
#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...