Submission #287820

# Submission time Handle Problem Language Result Execution time Memory
287820 2020-09-01T03:14:31 Z zecookiez Tree Rotations (POI11_rot) C++17
36 / 100
1000 ms 23544 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);
    int cur, case1 = 0, case2 = 0;
    for(auto i : left){
        cur = right.order_of_key(i);
        case1 += cur;
        case2 += len(right) - cur;
    }
    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 388 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 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 384 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 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 17 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 1528 KB Output is correct
2 Correct 16 ms 768 KB Output is correct
3 Correct 516 ms 1608 KB Output is correct
4 Correct 697 ms 1892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 3960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 279 ms 6136 KB Output is correct
2 Execution timed out 1037 ms 6520 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 23176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 1784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 23544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 5368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 4320 KB Time limit exceeded
2 Halted 0 ms 0 KB -