Submission #1085202

#TimeUsernameProblemLanguageResultExecution timeMemory
1085202eysbutnoUntitled (POI11_rot)C++17
36 / 100
1067 ms22980 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = array<int, 2>; #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int main() { cin.tie(0) -> sync_with_stdio(0); int n; cin >> n; const auto dfs = [&](auto &&self) -> pair<ll, Tree<int>> { int x; cin >> x; if (x == 0) { auto [inv_l, set_l] = self(self); auto [inv_r, set_r] = self(self); if (sz(set_l) > sz(set_r)) { set_l.swap(set_r); } ll opt_1 = 0, opt_2 = 0; for (int v : set_l) { int idx = set_r.order_of_key(v); opt_1 += idx; opt_2 += sz(set_r) - idx; } for (int v : set_l) { set_r.insert(v); } return {inv_l + inv_r + min(opt_1, opt_2), set_r}; } else { Tree<int> res; res.insert(x); return {0, res}; } }; cout << dfs(dfs).first << "\n"; }
#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...
#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...