Submission #886767

#TimeUsernameProblemLanguageResultExecution timeMemory
886767OAleksaUntitled (POI11_rot)C++14
36 / 100
1076 ms36300 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define f first #define s second #define int long long const int N = 2e5 + 69; int n, t = 1, ans; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ordered_set st[N]; int napravi() { int x; cin >> x; if (x == 0) { int l = napravi(); int r = napravi(); if (st[l].size() < st[r].size()) { st[l].swap(st[r]); swap(l, r); } int k1 = 0, k2 = 0; for (auto u : st[r]) { int x = st[l].order_of_key(u + 1); k1 += (int)st[l].size() - x; } //b a for (auto u : st[r]) { int x = st[l].order_of_key(u + 1); k2 += x; } for (auto u : st[r]) st[l].insert(u); st[r].clear(); ans += min(k1, k2); return l; } else { st[x].insert(x); return x; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("snowcow.in", "r", stdin); //freopen("snowcow.out", "w", stdout); int tt = 1; //cin >> tt; while (tt--) { cin >> n; napravi(); cout << ans; } return 0; }
#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...