Submission #280402

#TimeUsernameProblemLanguageResultExecution timeMemory
280402CaroLindaArranging Shoes (IOI19_shoes)C++14
100 / 100
227 ms22136 KiB
#include <bits/stdc++.h> #include "shoes.h" #define sz(x) (int)x.size() #define mkt make_tuple #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define ff first #define ss second #define eb emplace_back #define ll long long #define mk make_pair #define pii pair<int,int> #define debug printf #define all(x) x.begin(),x.end() const int MAXN = 1e5+10 ; 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> int freq[MAXN][2] ; int active ; set<int> types_left[MAXN] , types_right[MAXN] ; ordered_set o_set ; /* 6 -2 2 2 -2 -2 2 */ long long count_swaps(vector<int> v) { ll ans = 0LL ; for(int i = 0 ; i < sz(v) ; i++ ) { int x = abs(v[i]) ; if( v[i] < 0 ) { if( sz(types_right[x]) > 0 ) { int t = *types_right[x].begin() ; types_right[x].erase( types_right[x].begin() ) ; ans += (ll)( i - t ) ; o_set.erase( o_set.find(-t) ) ; ans -= o_set.order_of_key( -t ) ; } else { types_left[x].insert(i) ; o_set.insert(-i) ; } } else { if( sz(types_left[x]) > 0 ) { int t = *types_left[x].begin() ; types_left[x].erase( types_left[x].begin() ) ; ans += (ll)( i - t - 1 ) ; o_set.erase( o_set.find(-t) ) ; ans -= o_set.order_of_key(-t) ; } else { types_right[x].insert(i) ; o_set.insert(-i) ; } } } 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...