제출 #299024

#제출 시각아이디문제언어결과실행 시간메모리
299024REALITYNBArranging Shoes (IOI19_shoes)C++14
100 / 100
184 ms42616 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 5e5 ; vector<int> ft(mxn) ; void update(int i ){ for(;i<mxn;i+=(i&-i)) ft[i]++ ; } int query(int i ){ int ans = 0 ; for(;i>0;i-=(i&-i)) ans+=ft[i] ; return ans ; } long long count_swaps(vector<int> a){ #define int long long int n = a.size() ; int ans = 0 ; set<int> adj[n*3] ; for(int i=0;i<n;i++) adj[a[i]+n].insert(i) ; for(int i=0;i<n;i++){ if(a[i]==0) continue ; // cout <<a[i] << " " ; int oth = a[i]*-1 ; oth+=n ; a[i]+=n ; adj[a[i]].erase(i) ; int j = *(adj[oth].begin()) ; adj[oth].erase(adj[oth].begin()) ; int ze = query(j+1)-query(i+1) ; a[i]-=n ; ans+=j-i-(a[i]<0)-ze ; a[i]=0 ; a[j]= 0 ; update(1+i) ; update(j+1) ; } // cout << 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...