Submission #146237

#TimeUsernameProblemLanguageResultExecution timeMemory
146237achibasadzishviliArranging Shoes (IOI19_shoes)C++14
100 / 100
341 ms33016 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back 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> ordered_set ord; set<int>st[400005]; int n,a[400005],fix[400005],ind,k,f; vector<int>gg; int d(int x){ return ord.order_of_key(x); } ll count_swaps(vector<int>v){ ll ans = 0; int n = (int)v.size(); for(int i=1; i<=n; i++){ a[i] = v[i - 1]; st[a[i] + n].insert(i); } for(int i=1; i<=n; i++){ if(fix[i])continue; if(a[i] > 0)ans++; st[a[i] + n].erase(st[a[i] + n].find(i)); ind = (*st[-a[i] + n].begin()); fix[ind] = 1; st[-a[i] + n].erase(st[-a[i] + n].begin()); k = (int)ord.size() - d(i); f = (int)ord.size() - d(ind); ans += (ind + f) - (i + k) - 1; ord.insert(ind); } 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...