Submission #915647

#TimeUsernameProblemLanguageResultExecution timeMemory
915647SmuggingSpunArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms756 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; ll count_swaps(vector<int>s) { int n = s.size(); map<int, int>p; vector<int>a(n); for(int i = 0, index = 1; i < n; i++){ auto it = p.find(-s[i]); if(it != p.end()){ a[i] = it->second + (s[i] < 0 ? -1 : 1); p.erase(it); } else{ p[s[i]] = a[i] = index + int(s[i] > 0); index += 2; } } vector<int>bit(n + 1, 0); auto update = [&] (int p){ for(; p <= n; p += p & -p){ bit[p]++; } }; auto get = [&] (int p){ int ans = 0; for(; p > 0; p -= p & -p){ ans += bit[p]; } return ans; }; ll ans = 0; for(int i = 0; i < n; i++){ ans += i - get(a[i]); update(a[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...