Submission #915649

#TimeUsernameProblemLanguageResultExecution timeMemory
915649SmuggingSpunArranging Shoes (IOI19_shoes)C++14
100 / 100
483 ms149116 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, deque<int>>p; vector<int>a(n); for(int i = 0, index = 1; i < n; i++){ if(!p[-s[i]].empty()){ a[i] = p[-s[i]].front() + (s[i] < 0 ? -1 : 1); p[-s[i]].pop_front(); } else{ p[s[i]].push_back(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...