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"
constexpr int BASE = 31;
constexpr int MOD = 1e9 + 7;
constexpr int NMAX = 5e5 + 5;
int Power_Base[NMAX];
int Normal_Hash[21][NMAX];
int BrPerm_Hash[21][NMAX];
int Max_Pow = 19;
void init(int n, const char s[]) {
Power_Base[0] = BASE;
for (int i = 1; i <= Max_Pow; ++ i )
Power_Base[i] = (1LL * Power_Base[i-1] * Power_Base[i-1]) % MOD;
for (int i = 0; i < n; ++ i )
BrPerm_Hash[0][i] = s[i] - 'a';
for (int k = 1; k <= Max_Pow; ++ k )
for (int i = 0; i + (1<<k) - 1 < n; ++ i )
BrPerm_Hash[k][i] = (1LL * BrPerm_Hash[k-1][i] + (1LL * BrPerm_Hash[k-1][i+(1<<(k-1))] * Power_Base[Max_Pow-k]) % MOD) % MOD;
for (int k = 0; k <= Max_Pow; ++ k )
for (int i = n-1; i >= 0; -- i )
Normal_Hash[k][i] = ((s[i]-'a') + 1LL * Normal_Hash[k][i+1] * Power_Base[Max_Pow-k]) % MOD;
}
int query(int i, int k) {
int normal = (Normal_Hash[k][i] - (1LL * Normal_Hash[k][i+(1<<k)] * Power_Base[Max_Pow] % MOD) + MOD) % MOD;
int brperm = BrPerm_Hash[k][i];
if (normal == brperm) return 1;
else return 0;
}
# | 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... |