Submission #219769

#TimeUsernameProblemLanguageResultExecution timeMemory
219769VEGAnnArranging Shoes (IOI19_shoes)C++14
100 / 100
107 ms15096 KiB
#include <bits/stdc++.h> #include "shoes.h" #define all(x) x.begin(),x.end() #define PB push_back #define sz(x) ((int)x.size()) using namespace std; typedef long long ll; const int N = 200100; vector<int> vc[N]; ll ans = 0; int fen[N]; bool mrk[N]; int sum(int x){ int res = 0; for (; x >= 0; x = (x & (x + 1)) - 1) res += fen[x]; return res; } void upd(int x, int vl){ for (; x < N; x = (x | (x + 1))) fen[x] += vl; } long long count_swaps(std::vector<int> s) { int n = sz(s) / 2; for (int i = sz(s) - 1; i >= 0; i--) vc[s[i] + n].PB(i); for (int i = 0; i < sz(s); i++){ if (mrk[i]) continue; if (s[i] > 0) ans++; vc[s[i] + n].pop_back(); int real_i = i + sum(i); int j = vc[-s[i] + n].back(); vc[-s[i] + n].pop_back(); mrk[j] = 1; int real_j = sum(j) + j; ans += real_j - real_i - 1; upd(i, 1); upd(j, -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...