Submission #931834

# Submission time Handle Problem Language Result Execution time Memory
931834 2024-02-22T11:49:37 Z Muaath_5 Secret (JOI14_secret) C++17
6 / 100
379 ms 5116 KB
/*

Debugger/Idea: Ahmad Alhashim (@vahmad)

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

const int N = 1001;
const int DST_LOG = 10, 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) floor(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}];
}
# Verdict Execution time Memory Grader output
1 Correct 108 ms 3408 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
2 Partially correct 113 ms 3332 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 109 ms 3408 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 379 ms 5036 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 376 ms 5116 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 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
7 Partially correct 378 ms 5108 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 376 ms 5112 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 376 ms 5112 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 379 ms 4948 KB Output isn't correct - number of calls to Secret by Init = 8194, maximum number of calls to Secret by Query = 1