Submission #947656

# Submission time Handle Problem Language Result Execution time Memory
947656 2024-03-16T17:51:52 Z biank Secret (JOI14_secret) C++14
100 / 100
433 ms 4508 KB
#include <bits/stdc++.h>
#include "secret.h"

using namespace std;
 
const int MAX_N = 1000;
const int MAX_H = 10;
 
int val[MAX_H][MAX_N], n;
 
void build(int l, int r, int a[], int h) {
    int m = (l + r) / 2;
    val[h][m] = a[m];
    if (l == r) return;
    val[h][m + 1] = a[m + 1];
    for (int i = m + 2; i <= r; i++) {
        val[h][i] = Secret(val[h][i - 1], a[i]);
    }
    for (int i = m - 1; i >= l; i--) {
        val[h][i] = Secret(a[i], val[h][i + 1]);
    }
    build(l, m, a, h + 1);
    build(m + 1, r, a, h + 1);
}
 
void Init(int N, int a[]) {
    n = N;
    build(0, n - 1, a, 0);
}
 
int solve(int l, int r, int a, int b, int h) {
    if (l == r) return val[h][a];
    int m = (l + r) / 2;
    if (b <= m) return solve(l, m, a, b, h + 1);
    if (a > m) return solve(m + 1, r, a, b, h + 1);
    return Secret(val[h][a], val[h][b]);
}
 
int Query(int L, int R) {
    return solve(0, n - 1, L, R, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 111 ms 2652 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 110 ms 2768 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 138 ms 2812 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 384 ms 4376 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 400 ms 4508 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 429 ms 4504 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 431 ms 4348 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 433 ms 4344 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 385 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 388 ms 4344 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1