Submission #288255

#TimeUsernameProblemLanguageResultExecution timeMemory
288255amiratouArranging Shoes (IOI19_shoes)C++14
50 / 100
128 ms33316 KiB
#include "shoes.h" #include <bits/stdc++.h> #include "ext/pb_ds/assoc_container.hpp" using namespace std; using namespace __gnu_pbds; #define sz(x) (int)(x.size()) #define fi first #define se second template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef pair<int,int> ii; const int MX = (int)(1e5+5); int n; vector<int> vec[2*MX]; ll count_swaps(vector<int> s) { n=sz(s); ordered_set <ii> X; ll ans=0; for (int i = n-1; i >= 0; i--) { X.insert({i,s[i]}); if(s[i]>0)vec[s[i]].push_back(i); else vec[-s[i]+n].push_back(i); } while(!X.empty()){ ii f=(*X.begin()),m; if(f.se<0){ vec[-f.se+n].pop_back(); m={vec[-f.se].back(),-f.se}; vec[-f.se].pop_back(); } else{ vec[f.se].pop_back(); m={vec[f.se+n].back(),-f.se}; vec[f.se+n].pop_back(); } ans+=X.order_of_key(m)-1+(f.se>0); X.erase(X.begin()),X.erase(m); } 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...