#include "brperm.h"
#include <iostream>
using namespace std;
const int NMAX = 5e5;
const int LOGMAX = 19;
const int B = 29;
const int MOD = 1e9 + 7;
int dp[NMAX + 1][LOGMAX + 1][2];
int powB[NMAX + 1];
int h[NMAX + 1];
int N;
void init(int n, const char s[]){
N = n;
powB[0] = 1;
for(int i = 1; i <= NMAX; i++){
powB[i] = (1ll * powB[i - 1] * B) % MOD;
}
for(int i = 1; i <= n; i++){
h[i] = ((1ll * h[i - 1] * B) % MOD + (s[i - 1] - 'a' + 1)) % MOD;
}
int pw = 1, pwind = 0;
while(pw * 2 <= n){
pw *= 2;
pwind++;
}
for(int k = pwind; k >= 0; k--){
for(int j = 0; (1 << j) <= n; j++){
for(int i = 1; i <= n; i++){
if(j == 0){
dp[i][j][k & 1] = (s[i - 1] - 'a' + 1);
}else{
if(i + ((1 << j) - 1) * (1 << k) <= n){
dp[i][j][k & 1] = ((1ll * dp[i][j - 1][(k + 1) & 1] * powB[(1 << (j - 1))]) % MOD + dp[i + (1 << k)][j - 1][(k + 1) & 1]) % MOD;
}
}
}
}
}
return;
}
int query(int i, int k){
if(i + (1 << k) - 1 > N){
return 0;
}
++i;
int H1 = dp[i][k][0];
int H2 = (1ll * h[i + (1 << k) - 1] + MOD - ((1l * h[i - 1] * powB[(1 << k)]) % MOD)) % MOD;
return (H1 == H2);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
3 |
Correct |
97 ms |
23240 KB |
Output is correct |
4 |
Correct |
96 ms |
23248 KB |
Output is correct |
5 |
Correct |
96 ms |
23380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
83 ms |
168020 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
3 |
Correct |
97 ms |
23240 KB |
Output is correct |
4 |
Correct |
96 ms |
23248 KB |
Output is correct |
5 |
Correct |
96 ms |
23380 KB |
Output is correct |
6 |
Runtime error |
83 ms |
168020 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |