# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
931836 | Muaath_5 | Secret (JOI14_secret) | C++17 | 386 ms | 5204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
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}];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |