Submission #283534

#TimeUsernameProblemLanguageResultExecution timeMemory
283534ipaljakArranging Shoes (IOI19_shoes)C++14
10 / 100
3 ms2176 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " " << x << endl #define _ << " " << typedef long long llint; const int MAXN = 1e5 + 5; bool bio[MAXN]; int n; int nxt[2 * MAXN], loga[2 * MAXN]; vector<int> s; void init() { memset(nxt, -1, sizeof nxt); map<int, int> m; for (int i = n - 1; i >= 0; --i) { if (m.find(-s[i]) != m.end()) nxt[i] = m[-s[i]]; m[s[i]] = i; } } void add(int i) { for (; i < 2 * MAXN; i += i & -i) loga[i]++; } int sum(int lo, int hi) { int ret = 0; for (; hi > 0; hi -= hi & -hi) ret += loga[hi]; for (--lo; lo > 0; lo -= lo & -lo) ret -= loga[lo]; return ret; } llint count_swaps(vector<int> _s) { s = _s; n = (int) s.size(); init(); llint sol = 0; for (int i = 0; i < n; ++i) { if (bio[i]) continue; assert(nxt[i] != -1); int l = i, r = nxt[i]; bio[l] = bio[r] = true; sol += (llint) r - l - 1; sol -= sum(l + 1, r + 1); add(l + 1); add(r + 1); if (s[i] > 0) ++sol; } return sol; }
#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...