Submission #677055

#TimeUsernameProblemLanguageResultExecution timeMemory
677055hello_there_123Arranging Shoes (IOI19_shoes)C++17
100 / 100
525 ms148824 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; #define ll long long ll n; ll ft[200005]; inline ll ls(int x){return x & -x; } ll qry(ll p){ p++; if(p<1) return 0; ll r = 0; for(;p;p-=ls(p)) r+=ft[p]; return r; } void upd(ll p, ll v){ p++; for(;p<=n;p+=ls(p)) ft[p]+=v; } long long count_swaps(vector<int>s) { ll ans = 0; n = s.size(); map<ll,queue<ll> >mp; for(ll i=0;i<n;i++){ ll x = s[i]; mp[x].push(i); } bool arr[n+3]; memset(arr,0,sizeof(arr)); for(ll i=0;i<n;i++){ if(arr[i]) continue; mp[s[i]].pop(); ll first = mp[-s[i]].front(); mp[-s[i]].pop(); ans+=first-i-1-(qry(first)-qry(i-1)); upd(first,1); arr[first] = 1; if(s[i]>0) ans++; } 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...