Submission #201601

#TimeUsernameProblemLanguageResultExecution timeMemory
201601khulegubArranging Shoes (IOI19_shoes)C++14
0 / 100
11 ms9720 KiB
#include "shoes.h" #include <bits/stdc++.h> #define mp make_pair #define pb push_back #define xx first #define yy second #define ll(x) (x*2) + 1 #define rr(x) (x*2) + 2 using namespace std; typedef long long i64; int n; bool taken[200010]; vector<int> maap_l[200010], maap_r[200010]; i64 count_swaps(std::vector<int> s) { i64 ans = 0LL; n = s.size(); for (int i = n - 1; i >= 0; i--){ if (s[i] < 0) maap_l[s[i] * -1].pb(i); else maap_r[s[i]].pb(i); } for (int i = 0; i < n; i++){ if (!taken[i]){ int tmp; if (s[i] < 0){ tmp = maap_r[s[i] * -1].back(); maap_r[s[i] * -1].pop_back(); maap_l[s[i] * -1].pop_back(); } else{ tmp = maap_l[s[i]].back(); maap_l[s[i]].pop_back(); maap_r[s[i]].pop_back(); } taken[tmp] = 1; if (s[i] < 0){ ans += tmp - i - 1; } else{ ans += tmp - i; } for (int j = i; j <= tmp; j++) if (taken[j]) ans--; } } 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...