Submission #647806

# Submission time Handle Problem Language Result Execution time Memory
647806 2022-10-04T07:31:46 Z clams Secret (JOI14_secret) C++17
100 / 100
455 ms 4452 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;
const int LG = __lg(N) + 1;
const int LIM = 8000;

int n;
int a[N];
int dat[LG][N];
int msk[N];

void Rec(int l, int r, int lvl) {
    if (l == r) return;

    int m = (l + r) / 2;

    dat[lvl][m] = a[m];
    for (int i = m - 1; i >= l; i--) {
        dat[lvl][i] = Secret(a[i], dat[lvl][i + 1]); // notice the order
    }

    dat[lvl][m + 1] = a[m + 1];
    for (int i = m + 2; i <= r; i++) {
        dat[lvl][i] = Secret(dat[lvl][i - 1], a[i]);
    }

    for (int i = m + 1; i <= r; i++) {
        msk[i] |= (1 << lvl);
    }

    Rec(l, m, lvl + 1);
    Rec(m + 1, r, lvl + 1);
}

int Query(int l, int r) {
    if (l == r) return a[l];
    int lvl = __builtin_ctz(msk[l] ^ msk[r]);
    return Secret(dat[lvl][l], dat[lvl][r]);
}

void Init(int sz, int A[]) {
    copy(A, A + sz, a);
    n = sz;

    Rec(0, n - 1, 0);
}


# Verdict Execution time Memory Grader output
1 Correct 125 ms 2592 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 126 ms 2492 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 128 ms 2464 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 440 ms 4452 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 449 ms 4340 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 443 ms 4328 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 451 ms 4352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 448 ms 4428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 455 ms 4396 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 448 ms 4308 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1