답안 #1085214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085214 2024-09-07T17:13:48 Z eysbutno Tree Rotations (POI11_rot) C++17
27 / 100
93 ms 65536 KB
#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;
    int timer = 0;
    vector<ll> inv(3 * n);
    vector<Tree<int>> sets(3 * n);
    const auto dfs = [&](int idx, auto &&self) -> void {
        int x; cin >> x;
        if (x == 0) {
            int idx_l = ++timer;
            self(idx_l, self);
            int idx_r = ++timer;
            self(idx_r, self);
            if (sz(sets[idx_l]) > sz(sets[idx_r])) {
                sets[idx_l].swap(sets[idx_r]);
            }
            ll opt_1 = 0, opt_2 = 0;
            for (int v : sets[idx_l]) {
                int loc = sets[idx_r].order_of_key(v);
                opt_1 += loc;
                opt_2 += sz(sets[idx_r]) - loc;
            }
            for (int v : sets[idx_l]) {
                sets[idx_r].insert(v);
            }
            sets[idx_l].clear();
            inv[idx] = inv[idx_l] + inv[idx_r] + min(opt_1, opt_2);
            sets[idx] = move(sets[idx_r]);
        } else {
            sets[idx].insert(x);
        }
    };
    dfs(0, dfs);
    cout << inv[0] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1112 KB Output is correct
4 Correct 10 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 59 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 93 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -