Submission #1076541

#TimeUsernameProblemLanguageResultExecution timeMemory
1076541surguttiBrperm (RMI20_brperm)C++14
100 / 100
264 ms172220 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...