Submission #287817

# Submission time Handle Problem Language Result Execution time Memory
287817 2020-09-01T03:11:02 Z zecookiez Tree Rotations (POI11_rot) C++14
36 / 100
1000 ms 24824 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class C>constexpr int len(const C&c){return int(c.size());}
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int MAXN = 200005;
int N; long long ans;

ordered_set solve(){
    int A; cin >> A;
    if(A != 0){
        ordered_set arr; arr.insert(A);
        return arr;
    }
    ordered_set left = solve(), right = solve();
    if(left.size() > right.size()) swap(left, right);
    long long case1 = 0, case2 = 0;
    for(auto i : left){
        case1 += right.order_of_key(i);
        case2 += len(right) - right.order_of_key(i);
    }
    ans += min(case1, case2);
    for(auto i : left) right.insert(i);
    return right;
}

int main(){
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N; solve(); cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 17 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 1400 KB Output is correct
2 Correct 17 ms 768 KB Output is correct
3 Correct 516 ms 1528 KB Output is correct
4 Correct 708 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 3812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 291 ms 6520 KB Output is correct
2 Execution timed out 1085 ms 6432 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 23716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 1784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 24824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 5368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 4476 KB Time limit exceeded
2 Halted 0 ms 0 KB -