제출 #157134

#제출 시각아이디문제언어결과실행 시간메모리
157134NachoLibreArranging Shoes (IOI19_shoes)C++14
100 / 100
403 ms275096 KiB
#include <bits/stdc++.h> using namespace std; queue<int> q[2][200005]; bool bo[200005]; int ft[200005]; void gnk(int i) { while(i < 200005) { ++ft[i]; i += (i & -i); } } int pay(int i) { int tp = 0; while(i > 0) { tp += ft[i]; i -= (i & -i); } return tp; } long long count_swaps(vector<int> s) { long long rp = 0; int n = s.size(), payi = 0, a[n + 1]; for(int i = 1; i <= n; ++i) { a[i] = s[i - 1]; } for(int i = 1; i <= n; ++i) { if(a[i] < 0) q[0][-a[i]].push(i); else q[1][a[i]].push(i); } for(int i = 1; i <= n; ++i) { if(!bo[i]) { if(a[i] > 0) { q[1][a[i]].pop(); rp += q[0][a[i]].front() - i - (pay(q[0][a[i]].front()) - payi); gnk(q[0][a[i]].front()); bo[q[0][a[i]].front()] = 1; q[0][a[i]].pop(); } else { q[0][-a[i]].pop(); rp += q[1][-a[i]].front() - i - 1 - (pay(q[1][-a[i]].front()) - payi); gnk(q[1][-a[i]].front()); bo[q[1][-a[i]].front()] = 1; q[1][-a[i]].pop(); } } else { ++payi; } } return rp; }
#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...