# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
565980 | SSRS | Secret (JOI14_secret) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
template <typename T>
struct disjoint_sparse_table{
function<T(T, T)> f;
int N;
vector<T> A;
vector<vector<T>> D;
disjoint_sparse_table(vector<T> &A, function<T(T, T)> f): A(A), f(f){
int N2 = A.size();
N = 1;
int LOG = 0;
while (N < N2){
N *= 2;
LOG++;
}
A.resize(N);
D = vector<vector<T>>(LOG, vector<T>(N));
for (int i = 0; i < LOG; i++){
for (int j = 0; j < N; j += 1 << (i + 1)){
int d = 1 << i;
D[i][j + d - 1] = A[j + d - 1];
for (int k = j + d - 2; 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 < j + d * 2; 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]);
}
}
};
int f(int a, int b){
if (a == -1 || b == -1){
return -1;
}
return Secret(a, b);
}
disjoint_sparse_table<int> DST;
void Init(int N, int A[]){
vector<int> A2(N);
for (int i = 0; i < N; i++){
A2[i] = i;
}
DST = disjoint_sparse_table<int>(A2, f);
}
int Query(int L, int R){
L--;
return DST.query(L, R);
}