제출 #760173

#제출 시각아이디문제언어결과실행 시간메모리
760173thinknoexitArranging Shoes (IOI19_shoes)C++17
15 / 100
117 ms72536 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int fw[200200]; void update(int v, int w) { for (int i = v;i <= 200000;i += i & -i) fw[i] += w; } int query(int v) { int ans = 0; for (int i = v;i > 0;i -= i & -i) ans += fw[i]; return ans; } ll count_swaps(vector<int> v) { ll ans = 0; int n = (int)v.size(); queue<int> pos[100100]; queue<pair<int, int>> q; for (int i = 0;i < n;i++) { if (v[i] < 0) { q.push({ -v[i],i }); } else { pos[v[i]].push(i); } } int cnt = 0; while (!q.empty()) { auto x = q.front(); q.pop(); int val = x.first, i = x.second; ans += query(i) + i - cnt; update(1, 1), update(i + 1, -1); ans += query(pos[val].front()) + pos[val].front() - (cnt + 1); update(1, 1), update(pos[val].front() + 1, -1); pos[val].pop(); cnt += 2; } 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...