Submission #975570

#TimeUsernameProblemLanguageResultExecution timeMemory
975570marinalucaArranging Shoes (IOI19_shoes)C++17
50 / 100
259 ms147648 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O4") #pragma GCC optimize ("fast-math") #pragma GCC optimize ("unroll-loops") using namespace std; //#define int long long #define ll long long #define xx first #define yy second #define all (x) begin(x), end(x) #define cin fin #define cout fout ll count_swaps(vector <int> s){ int n = int (s.size()); unordered_map <int, queue<int>> frec; vector <int> bit(n + 1); int cnt = 0; for (int i = 0; i < n; ++ i) { int poz; if (frec[-s[i]].empty()){ poz = i + 1; frec[s[i]].push(poz); } else{ poz = frec[-s[i]].front(); frec[-s[i]].pop(); cnt += i; for (int ans = poz; ans; ans -= ans & (-ans)) cnt -= bit[ans]; if (s[i] < 0) cnt ++; } for (int ans = poz; ans <= n; ans += ans & (-ans)) bit[ans] ++; } return cnt; }
#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...