제출 #292318

#제출 시각아이디문제언어결과실행 시간메모리
292318Ruba_KArranging Shoes (IOI19_shoes)C++14
10 / 100
256 ms273272 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std ; const int N = 2e5 + 2 ; deque<int>pos[N]; struct BIT{ int sz; vector<int>v ; explicit BIT(int n){ sz = n + 1; v.resize(sz); } long long get(int i){ long long ret = 0; for(i++ ; i ; i -= ( i & -i)) ret += v[i]; return ret ; } void update(int i){ for(i ++ ; i <= sz ; i += (i & -i)) v[i] ++ ; } long long query(int a , int b){ return get(b) - get(a - 1); } }; int finish[N * 4]; long long count_swaps(vector<int> v) { int n = v.size() / 2; for(int i = 0 ; i < n * 2; i ++){ pos[n + v[i]].push_back(i); } long long ans = 0 ; BIT bit (n * 2 + 1); for(int i = 0 ;i < n * 2 ; i ++ ){ if(finish[i])continue ; int ab = -v[i] , p = pos[ab + n].front(); finish[p]++; pos[ab + n].pop_front(); pos[v[i] + n].pop_front(); int betwen = bit.query(i + 1 , p + 1); ans += p - i - 1 - betwen + (v[i] > 0 ? 1 : 0); bit.update( p + 1); } 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...