제출 #155176

#제출 시각아이디문제언어결과실행 시간메모리
155176flashmtArranging Shoes (IOI19_shoes)C++17
100 / 100
235 ms140024 KiB
#include <bits/stdc++.h> using namespace std; queue<int> q[200200]; int b[200200], bit[200200]; void add(int x) { for (int i = x; i <= 200000; i += i & -i) bit[i]++; } int get(int x) { int res = 0; for (int i = x; i; i -= i & -i) res += bit[i]; return res; } long long count_swaps(vector<int> a) { int n = a.size() / 2, id = 0; for (int i = 0; i < n * 2; i++) if (q[n - a[i]].empty()) { q[a[i] + n].push(i); b[i] = id * 2; id++; } else { int j = q[n - a[i]].front(); q[n - a[i]].pop(); b[i] = b[j] + 1; if (a[i] < 0) swap(b[i], b[j]); } long long ans = 0; for (int i = 0; i < n * 2; i++) { ans += i - get(b[i]); add(b[i] + 1); } return ans; }
#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...