Submission #931837

# Submission time Handle Problem Language Result Execution time Memory
931837 2024-02-22T11:53:12 Z Muaath_5 Secret (JOI14_secret) C++17
0 / 100
374 ms 4468 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][r], dst[lvl][l]);
    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 Incorrect 98 ms 2648 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 306260492.
2 Incorrect 100 ms 2808 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 654837857.
3 Incorrect 100 ms 2728 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 472907800.
4 Incorrect 368 ms 4468 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 363512416.
5 Incorrect 364 ms 4268 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 531251482.
6 Incorrect 368 ms 4432 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 168916465.
7 Incorrect 372 ms 4364 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 199265362.
8 Incorrect 374 ms 4448 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 469836240.
9 Incorrect 371 ms 4320 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 810957935.
10 Incorrect 372 ms 4268 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 611593612.