Submission #489564

# Submission time Handle Problem Language Result Execution time Memory
489564 2021-11-23T08:55:46 Z danikoynov Secret (JOI14_secret) C++14
100 / 100
459 ms 4456 KB
#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
1 Correct 136 ms 2388 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 135 ms 2504 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 126 ms 2400 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 443 ms 4276 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 441 ms 4264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 440 ms 4228 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 454 ms 4224 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 459 ms 4276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 445 ms 4204 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 443 ms 4456 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1