Submission #830169

#TimeUsernameProblemLanguageResultExecution timeMemory
830169GusterGoose27Arranging Shoes (IOI19_shoes)C++17
10 / 100
3 ms5024 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+5; typedef long long ll; int bit[MAXN]; int nxt[MAXN]; int n; void upd(int p, int v) { for (; p < n; p |= (p+1)) bit[p] += v; } int sum(int p) { int s = 0; for (p++; p > 0; p &= (p-1)) s += bit[p-1]; return s; } vector<int> occ[MAXN]; bool matched[MAXN]; int _abs(int x) { return x < 0 ? -x : x; } ll count_swaps(vector<int> s) { n = s.size(); for (int i = 0; i < n; i++) { int x = _abs(s[i]); if (occ[x].size() && s[occ[x].back()] != s[i]) { nxt[occ[x].back()] = i; occ[x].pop_back(); } else occ[x].push_back(i); } for (int i = 1; i <= n/2; i++) assert(occ[i].empty()); ll ans = 0; for (int i = 0; i < n; i++) { if (matched[i]) continue; int dist = nxt[i]+sum(nxt[i])-(s[i] < 0); ans += dist; upd(i, -1); upd(nxt[i], -1); matched[i] = matched[nxt[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...