Submission #877540

# Submission time Handle Problem Language Result Execution time Memory
877540 2023-11-23T09:53:14 Z Ivkosqn Secret (JOI14_secret) C++14
100 / 100
366 ms 11968 KB
#include <bits/stdc++.h>
#include "secret.h"
#define endl '\n'

using namespace std;

const int maxn = 1024;
int pref[maxn][maxn], suff[maxn][maxn];
int lf[maxn], rg[maxn], a[maxn];
vector<int> mids;

void divide(int l, int r){
    if(l > r)
        return;
    if(l == r){
        suff[l][l] = a[l];
        lf[l] = l;
        rg[l] = l;
        mids.push_back(l);
        return;
    }
    int mid = (l + r) / 2;
    mids.push_back(mid);
    divide(l, mid - 1);
    divide(mid + 1, r);
    lf[mid] = l, rg[mid] = r;
    suff[mid][mid] = a[mid];
    pref[mid][mid + 1] = a[mid + 1];
    for(int i = mid - 1;i >= l;i--)
        suff[mid][i] = Secret(a[i], suff[mid][i + 1]);
    for(int i = mid + 2;i <= r;i++)
        pref[mid][i] = Secret(pref[mid][i - 1], a[i]);
}

void Init(int n, int A[]){
    for(int i = 0;i < n;i++)
        a[i] = A[i];
    divide(0, n - 1);
}

int Query(int l, int r){
    for(int x : mids){
        if(lf[x] <= l && rg[x] >= r && x >= l && x <= r){
            int ans = suff[x][l];
            if(x != r)
                ans = Secret(ans, pref[x][r]);
            return ans;
        }
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 105 ms 10936 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 102 ms 10836 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Correct 101 ms 10832 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
4 Correct 363 ms 11968 KB Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1
5 Correct 357 ms 11600 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
6 Correct 360 ms 11696 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
7 Correct 353 ms 11788 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 366 ms 11684 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 360 ms 11688 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 359 ms 11796 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1