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 "brperm.h"
typedef long long LL;
const LL mod = 1e9 + 696969;
const LL base = 2137;
const int L = 20;
const int N = 1 << L;
int n;
LL pw[N + 1], h1[L][N], h2[L][N];
void init(int _n, const char s[]) {
n = _n;
pw[0] = 1;
for (int i = 1; i <= N; i++)
pw[i] = pw[i - 1] * base % mod;
for (int h = 0; h < L; h++)
for (int i = n - 1; i >= 0; i--)
h1[h][i] = (s[i] + h1[h][i + 1] * pw[1 << h]) % mod;
for (int i = 0; i < n; i++)
h2[0][i] = s[i];
for (int h = 0; h + 1 < L; h++)
for (int i = 0; i < n; i++)
h2[h + 1][i] = (h2[h][i] + pw[(1 << (L - 2 - h))] * h2[h][i + (1 << h)]) % mod;
}
int query(int i, int k) {
if (i + (1 << k) > n)
return 0;
int l = L - 1 - k;
LL h = (h1[l][i] - h1[l][i + (1 << k)] * pw[1 << (L - 1)] % mod + mod) % mod;
return h == h2[k][i];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |