Submission #143379

#TimeUsernameProblemLanguageResultExecution timeMemory
143379ondrahArranging Shoes (IOI19_shoes)C++14
85 / 100
1016 ms39504 KiB
#include "shoes.h" #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #include <set> #include <map> using namespace std; using namespace __gnu_pbds; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; long long count_swaps(std::vector<int> s) { long long ans = 0; int n = s.size(); ordered_set els; map<int, set<int>> M; for(int i = 0; i < n; i++) { els.insert(i); M[s[i]].insert(i); } for(int i = 0; i < n; i++) { if(s[i] == n+2) continue; int j = *M[-s[i]].begin(); M[s[i]].erase(M[s[i]].begin()); M[-s[i]].erase(M[-s[i]].begin()); int pos1 = els.order_of_key(i); int pos2 = els.order_of_key(j); els.erase(els.find(j)); ans += pos2-pos1-1; if(s[i] > 0) ans++; s[i] = s[j] = n+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...