# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489564 | danikoynov | Secret (JOI14_secret) | C++14 | 459 ms | 4456 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;
const int maxn = 1010, maxlog = 15;
int dp[maxlog][maxn], arr[maxn], n;
void divide(int left, int right, int depth)
{
if (left == right)
{
dp[depth][left] = arr[left];
return;
}
int mid = (left + right) / 2;
dp[depth][mid] = arr[mid];
for (int i = mid - 1; i >= left; i --)
{
dp[depth][i] = Secret(arr[i], dp[depth][i + 1]);
///cout << depth << " " << i << " " << arr[i] << " " << dp[depth][i + 1] << endl;
}
dp[depth][mid + 1] = arr[mid + 1];
for (int i = mid + 2; i <= right; i ++)
dp[depth][i] = Secret(dp[depth][i - 1], arr[i]);
divide(left, mid, depth + 1);
divide(mid + 1, right, depth + 1);
}
void Init(int m, int a[])
{
n = m;
for (int i = 0; i < n; i ++)
arr[i] = a[i];
divide(0, n - 1, 1);
}
int Query(int l, int r)
{
int lf = 0, rf = n - 1, depth = 1;
while(true)
{
int mf = (lf + rf) / 2;
if (lf == rf)
{
return dp[depth][lf];
}
if (r <= mf)
{
rf = mf;
depth ++;
continue;
}
if (l > mf)
{
lf = mf + 1;
depth ++;
continue;
}
int ans = Secret(dp[depth][l], dp[depth][r]);
return ans;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |