Submission #891441

#TimeUsernameProblemLanguageResultExecution timeMemory
891441Muhammad_AneeqArranging Shoes (IOI19_shoes)C++17
100 / 100
793 ms164984 KiB
#include <set> #include <vector> #include <algorithm> #include <map> #include <deque> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> long long count_swaps(vector<int>s) { int n=s.size()/2; map<int,deque<int>>d; for (int i=0;i<2*n;i++) d[s[i]].push_back(i); map<int,int>vis; ordered_set cur; long long ans=0; for (int i=0;i<2*n;i++) { if (vis[i]) continue; int z=cur.order_of_key(d[-s[i]].front()); z=d[-s[i]].front()-z-1; if (s[i]>0) ans+=z+1; else ans+=z; cur.insert(d[s[i]].front()); cur.insert(d[-s[i]].front()); vis[d[s[i]].front()]=vis[d[-s[i]].front()]=1; d[s[i]].pop_front(); d[-s[i]].pop_front(); } 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...