Submission #249176

#TimeUsernameProblemLanguageResultExecution timeMemory
249176Dilshod_ImomovArranging Shoes (IOI19_shoes)C++17
10 / 100
1098 ms27764 KiB
# include <bits/stdc++.h> # define ll long long using namespace std; ll count_swaps( vector < int > s ) { ll n = s.size(), ans = 0, sz = 0; vector < ll > ids, used(n); map < ll , vector < ll > > vc; for ( ll i = 0; i < n; i++ ) { vc[s[i]].push_back( i ); } // cout << "Done 1" << endl; for ( ll i = 0; i < n; i++ ) { if ( used[i] ) { continue; } ll l = i, r = *vc[-s[i]].begin(); // cout << "Done 2 " << l << ' ' << r << '\n'; vc[ s[i] ].erase( vc[ s[i] ].begin() ); ll rr = r; used[r] = 1; vc[-s[i]].erase( vc[-s[i]].begin() ); ll x = upper_bound( ids.begin(), ids.end(), i ) - ids.begin(); x = sz - x; l += x; x = upper_bound( ids.begin(), ids.end(), r ) - ids.begin(); x = sz - x; r += x; ans += r - l - 1; if ( s[i] > 0 ) { ans++; } sz++; ids.push_back( rr ); } return ans; } /* int main() { ll n; cin >> n; vector < ll > 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...