# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
837759 | danitro | Secret (JOI14_secret) | C++14 | 412 ms | 4492 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.
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
#define MAX 1024
int table[25][MAX], n;
void build(int n, int a[], int l, int r, int level)
{
if(l > r)return;
if(l == r)
{
table[level][l] = a[l];
return;
}
int mid = (l + r) / 2;
table[level][mid + 1] = a[mid + 1];
for(int i = mid + 2; i <= r; i++)table[level][i] = Secret(table[level][i - 1], a[i]);
table[level][mid] = a[mid];
for(int i = mid - 1; i >= l; i--)table[level][i] = Secret(a[i], table[level][i + 1]);
build(n, a, l, mid, level + 1);
build(n, a, mid + 1, r, level + 1);
return;
}
void Init(int N, int A[])
{
n = N;
build(N, A, 0, n - 1, 0);
}
int Query(int L, int R)
{
int l = 0, r = n - 1, mid, lev = 0, opt;
while(l <= L && R <= r && r - l > 0)
{
mid = (l + r) / 2;
if(L > mid)l = mid + 1;
else r = mid;
opt = lev++;
}
if(L == R)return table[opt][L];
return Secret(table[opt][L], table[opt][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |