Submission #312992

# Submission time Handle Problem Language Result Execution time Memory
312992 2020-10-14T22:26:43 Z thecodingwizard popa (BOI18_popa) C++11
100 / 100
129 ms 504 KB
#include <bits/stdc++.h>
#include "popa.h"

using namespace std;

int solve(int N, int *L, int *R) {
    for (int i = 0; i < N; i++) {
        L[i] = R[i] = -1;
    }
    int root = -1;
    for (int i = 0; i < N; i++) {
        if (root == -1) {
            root = i;
            continue;
        }
        vector<int> nodes;
        int cur = root;
        while (cur != -1) {
            nodes.push_back(cur);
            cur = R[cur];
        }
        for (int idx = nodes.size()-1; idx >= 0; idx--) {
            cur = nodes[idx];
            if (query(cur, cur, cur, i)) {
                R[cur] = i;
                break;
            }
            if (idx > 0) {
                int par = nodes[idx-1];
                R[par] = i;
            } else {
                root = i;
            }
            R[cur] = L[i];
            L[i] = cur;
        }
    }
    return root;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 10 ms 256 KB Output is correct
3 Correct 11 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 372 KB Output is correct
2 Correct 100 ms 504 KB Output is correct
3 Correct 67 ms 376 KB Output is correct
4 Correct 95 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 384 KB Output is correct
2 Correct 109 ms 376 KB Output is correct
3 Correct 98 ms 504 KB Output is correct
4 Correct 129 ms 496 KB Output is correct