Submission #1075392

#TimeUsernameProblemLanguageResultExecution timeMemory
1075392juicyArranging Shoes (IOI19_shoes)C++17
100 / 100
207 ms76044 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> s) { int n = s.size(); vector<int> ft(n + 1); auto up = [&](int i, int x) { for (; i; i -= i & -i) { ft[i] += x; } }; auto qry = [&](int i) { int res = 0; for (; i <= n; i += i & -i) { res += ft[i]; } return res; }; map<int, deque<int>> dq; long long res = 0; for (int i = 0; i < n; ++i) { if (dq.count(-s[i]) && dq[-s[i]].size()) { int j = dq[-s[i]].front(); dq[-s[i]].pop_front(); up(j + 1, 1); res += qry(j + 2) + (s[i] < 0); } else { dq[s[i]].push_back(i); up(i + 1, 1); } } return res; }
#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...