답안 #931836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931836 2024-02-22T11:52:21 Z Muaath_5 비밀 (JOI14_secret) C++17
6 / 100
386 ms 5204 KB
/*

Debugger/Idea: Ahmad Alhashim (@vahmad)

*/
#include <bits/stdc++.h>
#include "secret.h"
#define ll long long
using namespace std;

const int N = 2001;
const int DST_LOG = 12, DST_SIZE = (1 << DST_LOG);

int Secret(int X, int Y);
void Init(int N, int A[]);
int Query(int L, int R);

int n, a[DST_SIZE], dst[DST_LOG][DST_SIZE];


//#define __lg(x) ceil(log2(x))


void build_rec(int l, int r, int lvl)
{
    const int md = (l + r) / 2;
    dst[lvl][md] = a[md];
    for (int i = md + 1; i < r; i++) {
        dst[lvl][i] = Secret(dst[lvl][i - 1], a[i]);
    }
    dst[lvl][md - 1] = a[md - 1];
    for (int i = md - 2; i >= l; i--) {
        dst[lvl][i] = Secret(a[i], dst[lvl][i + 1]);
    }
    if (lvl == 0) return;
    build_rec(l, md, lvl - 1);
    build_rec(md, r, lvl - 1);
}

void build() {
    int levels_count = __lg(n);
    build_rec(0, (1 << (levels_count + 1)), levels_count);
}

int query(int l, int r)
{
    const int lvl = 31 - __builtin_clz(l ^ r);
    if (l == r) return a[l];
    int res = Secret(dst[lvl][l], dst[lvl][r]);
    return res;
}



void Init(int N, int A[])
{
    n = N;
    for (int i = 0; i < N; i++) {
        a[i] = A[i];
    }
    build();
}

map<pair<int, int>, int> mp;
int Query(int L, int R)
{
    if (mp.find({L, R}) == mp.end())
        return mp[{L, R}] = query(L, R);
    return mp[{L, R}];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 3156 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
2 Partially correct 110 ms 3240 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
3 Partially correct 117 ms 3492 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
4 Partially correct 376 ms 4944 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
5 Partially correct 386 ms 5080 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
6 Partially correct 376 ms 4948 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
7 Partially correct 378 ms 5204 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
8 Partially correct 377 ms 4944 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
9 Partially correct 385 ms 5184 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1
10 Partially correct 376 ms 5028 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1