답안 #780758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780758 2023-07-12T12:45:21 Z borisAngelov 비밀 (JOI14_secret) C++17
100 / 100
396 ms 4436 KB
#include "secret.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1024;
const int max_log = 15;

int n;
int a[maxn];

int precompute[maxn][max_log];

void divide(int depth, int l, int r)
{
    if (l == r)
    {
        precompute[l][depth] = a[l];
        return;
    }

    int mid = (l + r) / 2;

    precompute[mid][depth] = a[mid];

    for (int i = mid - 1; i >= l; --i)
    {
        precompute[i][depth] = Secret(a[i], precompute[i + 1][depth]);
    }

    precompute[mid + 1][depth] = a[mid + 1];

    for (int i = mid + 2; i <= r; ++i)
    {
        precompute[i][depth] = Secret(precompute[i - 1][depth], a[i]);
    }

    divide(depth + 1, l, mid);
    divide(depth + 1, mid + 1, r);
}

void Init(int N, int Arr[])
{
    n = N;

    for (int i = 0; i < n; ++i)
    {
        a[i] = Arr[i];
    }

    divide(0, 0, n - 1);
}

int recurse(int depth, int l, int r, int ql, int qr)
{
    if (l == r)
    {
        return precompute[l][depth];
    }

    int mid = (l + r) / 2;

    if (qr <= mid)
    {
        return recurse(depth + 1, l, mid, ql, qr);
    }

    if (ql >= mid + 1)
    {
        return recurse(depth + 1, mid + 1, r, ql, qr);
    }

    return Secret(precompute[ql][depth], precompute[qr][depth]);
}

int Query(int L, int R)
{
    int l = L;
    int r = R;

    return recurse(0, 0, n - 1, l, r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 2392 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 111 ms 2484 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 124 ms 2440 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 389 ms 4436 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 383 ms 4424 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 387 ms 4400 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 380 ms 4300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 388 ms 4412 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 396 ms 4408 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 392 ms 4416 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1