Submission #289568

#TimeUsernameProblemLanguageResultExecution timeMemory
289568nekiArranging Shoes (IOI19_shoes)C++14
100 / 100
354 ms360312 KiB
#include "shoes.h" #include <bits/stdc++.h> #define loop(i, a, b) for(long long i=a;i<b;i++) #define pool(i, a, b) for(long long i=a-1;i>=b;i--) #define fore(i, a) for(auto&& i:a) #define fi first #define se second #define ps(a) push_back(a) #define pb(a) pop_back(a) #define sc scanf #define vc vector #define pa pair<ll, ll> #define ll long long #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define llmax LLONG_MAX/2 #define llmin -LLONG_MAX/2 using namespace std; #define mn 262144 #define pa pair<ll, ll> #define ld long double queue<ll> poi[mn][2]; ll t[2 * mn]; void upd(ll l, ll r, ll val=1){ for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){ if(l&1) t[l++]+=val; if(r&1) t[--r]+=val; } } ll get(ll pos){ ll ret=0; for(pos+=mn;pos>0;pos>>=1) ret+=t[pos]; return ret; } long long int count_swaps(vc<int> a){ ll n=a.size()/2; ll ans=0; loop(i, 0, 2* n){ ll t=a[i]; if(poi[abs(t)][t<0].size()){ ll match=poi[abs(t)][t<0].front();poi[abs(t)][t<0].pop(); ans+=i-get(match)-match; if(t>0) ans--; upd(match, i); } else poi[abs(t)][t>0].push(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...