// 假设字符串由小写字母构成 int trie[SIZE][26], tot = 1; // Trie的插入 void insert(char* str) { int len = strlen(str), p = 1; for (int k = 0; k < len; k++) { int ch = str[k]-'a'; if (trie[p][ch] == 0) trie[p][ch] = ++tot; p = trie[p][ch]; } end[p] = true; } // Trie…
void ST_prework() { for (int i = 1; i <= n; i++) f[i][0] = a[i]; int t = log(n) / log(2) + 1; for (int j = 1; j < t; j++) for (int i = 1; i <= n - (1<<j) + 1; i++) f[i][j] = max(f[i][j-1], f[i + (1<<(j-1))][j-1]); } int ST_query(int l…
// 快速幂,求a^b mod p int power(int a, int b, int p) { int ans = 1; for (; b; b >>= 1) { if (b & 1) ans = (long long)ans * a % p; a = (long long)a * a % p; } return ans; } // 64位整数乘法的O(log b)算法 long long mul(long long a, long long b, long long p) {…