Submission #251920

#TimeUsernameProblemLanguageResultExecution timeMemory
251920Dilshod_ImomovArranging Shoes (IOI19_shoes)C++17
100 / 100
332 ms277624 KiB
# include <bits/stdc++.h> # define ll long long # define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int MAX_N = 100007; ll count_swaps( vector < int > s ) { speed; ll n = s.size(), sz = 0; ll ans = 0; vector < int > used(n); oset ids; vector < queue < int > > vc(4 * MAX_N); for ( int i = 0; i < n; i++ ) { s[i] += MAX_N; vc[s[i]].push( i ); } // cout << "Done 1" << endl; for ( int i = 0; i < n; i++ ) { if ( used[i] ) { continue; } s[i] -= MAX_N; int l = i, r = vc[-s[i] + MAX_N].front(); // cout << "Done 2 " << l << ' ' << r << endl; vc[ s[i] + MAX_N ].pop(); int rr = r; used[r] = 1; vc[-s[i] + MAX_N].pop(); int x = sz - ids.order_of_key(i + 1); l += x; x = sz - ids.order_of_key(r + 1); r += x; ans += r - l - 1; if ( s[i] > 0 ) { ans++; } sz++; ids.insert( rr ); } return ans; } /* int main() { ll n; cin >> n; vector < int > S(2 * n); for ( ll i = 0; i < 2 * n; i++ ) { cin >> S[i]; } cout << count_swaps( S ); } */
#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...