Submission #1047304

#TimeUsernameProblemLanguageResultExecution timeMemory
1047304Onur_IlgazArranging Shoes (IOI19_shoes)C++17
0 / 100
10 ms1992 KiB
#include "shoes.h" #include <bits/stdc++.h> 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<int> s) { int n = s.size(); return (n / 2) * (n / 2 - 1) / 2; 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...