답안 #618316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618316 2022-08-02T04:15:30 Z Shreyan_Paliwal 비밀 (JOI14_secret) C++17
100 / 100
476 ms 4320 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000;
const int maxlvl = 10;

int n;
int V[maxn];
int DVC[maxlvl][maxn];

void create(int lvl, int l, int r, int A[]) {
    if (l == r) {
        DVC[lvl][l] = A[l];
        return;
    }
    int m = (l + r) >> 1;
    // left side
    DVC[lvl][m] = A[m];
    for (int i = m - 1; i >= l; i--) DVC[lvl][i] = Secret(A[i], DVC[lvl][i + 1]);
    // right side
    DVC[lvl][m + 1] = A[m + 1];
    for (int i = m + 2; i <= r; i++) DVC[lvl][i] = Secret(DVC[lvl][i - 1], A[i]);

    create(lvl + 1, l, m, A);
    create(lvl + 1, m + 1, r, A);
}

int get(int lvl, int l, int r, int L, int R) {
    if (l == r) return DVC[lvl][L];
    int m = (l + r) >> 1;
    if (R <= m) return get(lvl + 1, l, m, L, R);
    if (L >= m+1) return get(lvl + 1, m+1, r, L, R);
    return Secret(DVC[lvl][L], DVC[lvl][R]);
}

void Init(int N, int A[]) {

    n = N;
    create(0, 0, n - 1, A);
}

int Query(int L, int R) {
    return get(0, 0, n - 1, L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 2324 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 135 ms 2392 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 135 ms 2336 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 462 ms 4248 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 438 ms 4288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 445 ms 4292 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 455 ms 4296 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 461 ms 4320 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 476 ms 4296 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 457 ms 4288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1