제출 #1047279

#제출 시각아이디문제언어결과실행 시간메모리
1047279vjudge1Arranging Shoes (IOI19_shoes)C++17
10 / 100
0 ms348 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back struct F{ vector<int> T; int n; F(int nn){ n=nn; T.resize(n + 1, 0); } void add(int v){ while(v <= n){ T[v]++; v += v&(-v); } } int get(int v){ int res=0; while(v>0){ res += T[v]; v -= (v&-v); } return res; } }; long long count_swaps(std::vector<int> s) { int n = s.size() + 5; vector<deque<int>> pos(n + n); ll ans = 0; int m = s.size(); F f(m); for(int i = m-1; i >= 0; --i){ if(s[i] < 0) pos[-s[i]].push_front(i); else pos[s[i] + n].push_front(i); } vector<int> taken(m); for(int i = 0; i < m; ++i){ if(taken[i]) continue; if(s[i] < 0){ int v = pos[-s[i] + n].front(); pos[-s[i] + n].pop_front(); int num = f.get(v) - f.get(i + 1); f.add(v); ans += v - i - 1 - num; taken[v] = 1; pos[-s[i]].pop_front(); }else{ int v = pos[s[i]].front(); pos[s[i]].pop_front(); int num = f.get(v) - f.get(i + 1); f.add(v); ans += v - i - num; taken[v] = 1; pos[s[i]+n].pop_front(); } // cout << ans << ' '; } // for(int i = 0; i < m; i += 2){ // for(int j = i + 1; j < m; ++j){ // if(abs(s[i]) == abs(s[j]) && s[i] == -s[j]){ // for(int l = j - 1; l > i; --l){ // swap(s[l], s[l + 1]); // ++ans; // // cout << l << ' '; // } // if(s[i] > s[i + 1]) swap(s[i], s[i + 1]), ++ans; // break; // } // } // // cout << '\n'; // } 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...