제출 #1047310

#제출 시각아이디문제언어결과실행 시간메모리
1047310Onur_IlgazArranging Shoes (IOI19_shoes)C++17
100 / 100
347 ms147676 KiB
#include "shoes.h" #include <bits/stdc++.h> #define int long long using namespace std; struct fw { int n; vector <int> t; fw(int size): n(size), t(n + 1) {} void update(int ind, int x) { ind++; while(ind <= n) { t[ind] += x; ind += ind & (-ind); } } int query(int ind) { int ans = 0; ind++; while(ind) { ans += t[ind]; ind -= ind & (-ind); } return ans; } }; long long count_swaps(std::vector<int32_t> s) { int n = s.size(); fw t(n); map <int, queue<int> > mp; int ans = 0; for(int i = 0; i < n; i++) { if(!mp[-s[i]].empty()) { int ind = mp[-s[i]].front(); t.update(ind + 1, 1); t.update(i, -1); ind += t.query(ind); // cout << i << " " << ind << "\n"; mp[-s[i]].pop(); ans += (i - ind) - (s[i] > 0); } else { mp[s[i]].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...