# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566073 | 2022-05-21T18:05:13 Z | SSRS | Secret (JOI14_secret) | C++14 | 460 ms | 4568 KB |
#include <bits/stdc++.h> #include "secret.h" using namespace std; template <typename T> struct disjoint_sparse_table{ function<T(T, T)> f; vector<T> A; vector<vector<T>> D; disjoint_sparse_table(){ } disjoint_sparse_table(vector<T> &A, function<T(T, T)> f): A(A), f(f){ int N = A.size(); int LOG = 32 - __builtin_clz(N - 1); D = vector<vector<T>>(LOG, vector<T>(N)); for (int i = 0; i < LOG; i++){ for (int j = 0; j + (1 << i) < N; j += 1 << (i + 1)){ int d = 1 << i; int x = min(j + d - 1, N - 1); D[i][x] = A[x]; for (int k = x - 1; k >= j; k--){ D[i][k] = f(A[k], D[i][k + 1]); } D[i][j + d] = A[j + d]; for (int k = j + d + 1; k < min(j + d * 2, N); k++){ D[i][k] = f(D[i][k - 1], A[k]); } } } } T query(int L, int R){ if (R - L == 1){ return A[L]; } else { R--; int b = 31 - __builtin_clz(R ^ L); return f(D[b][L], D[b][R]); } } }; disjoint_sparse_table<int> DST; void Init(int N, int A[]){ vector<int> A2(N); for (int i = 0; i < N; i++){ A2[i] = A[i]; } DST = disjoint_sparse_table<int>(A2, Secret); } int Query(int L, int R){ R++; return DST.query(L, R); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 126 ms | 2352 KB | Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 | Correct | 121 ms | 2372 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 | 2456 KB | Output is correct - number of calls to Secret by Init = 4097, maximum number of calls to Secret by Query = 1 |
4 | Correct | 436 ms | 4416 KB | Output is correct - number of calls to Secret by Init = 7979, maximum number of calls to Secret by Query = 1 |
5 | Correct | 442 ms | 4568 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
6 | Correct | 460 ms | 4424 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
7 | Correct | 441 ms | 4460 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
8 | Correct | 444 ms | 4416 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
9 | Correct | 450 ms | 4488 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
10 | Correct | 438 ms | 4344 KB | Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |