Submission #288265

#TimeUsernameProblemLanguageResultExecution timeMemory
288265amiratouArranging Shoes (IOI19_shoes)C++14
100 / 100
362 ms26472 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,N; vector<int> vec[2*MX]; ll count_swaps(vector<int> s) { n=sz(s); N=n/2; 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...