#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];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
8 ms |
9204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
8 ms |
9204 KB |
Output is correct |
3 |
Correct |
53 ms |
41300 KB |
Output is correct |
4 |
Correct |
57 ms |
41300 KB |
Output is correct |
5 |
Correct |
55 ms |
41300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
172220 KB |
Output is correct |
2 |
Correct |
264 ms |
171860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
8 ms |
9204 KB |
Output is correct |
3 |
Correct |
53 ms |
41300 KB |
Output is correct |
4 |
Correct |
57 ms |
41300 KB |
Output is correct |
5 |
Correct |
55 ms |
41300 KB |
Output is correct |
6 |
Correct |
240 ms |
172220 KB |
Output is correct |
7 |
Correct |
264 ms |
171860 KB |
Output is correct |
8 |
Correct |
258 ms |
171860 KB |
Output is correct |
9 |
Correct |
250 ms |
171880 KB |
Output is correct |
10 |
Correct |
248 ms |
171860 KB |
Output is correct |