This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://oj.uz/problem/view/POI11_rot
// State: Writing...
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#include <ios>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long ans = 0;
Tree <int> solve(){
int x;
Tree<int> s1,s2;
cin >> x;
if (x != 0){
s1.insert(x);
return s1;
}
s1 = solve();
s2 = solve();
if (s1.size() < s2.size()) s1.swap(s2);
//auto i1 = s1.begin(), i2 = s2.begin();
long long nghich = 0;
for (int v : s2)
nghich = nghich + s1.order_of_key(v);
ans = ans + min((long long)nghich,(long long)s1.size()*(int)s2.size() - nghich);
//cout << ans << endl;
for (int v : s2){
s1.insert(v);
}
return s1;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);cout.tie(NULL);
int n;
cin >> n;
solve();
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |