We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
struct node {
int next[26];
int len;
int sufflink;
int num, l, r;
};
int len;
char s[MAXN];
node tree[MAXN];
int num; // node 1 - root with len -1, node 2 - root with len 0
int suff; // max suffix palindrome
long long ans;
vi adj[ MAXN ];
viii A;
int n, q;
bool addLetter(int pos) {
int cur = suff, curlen = 0;
int let = s[pos] - 'a';
void dfs( int u ) {
for( auto it: adj[u] ) {
dfs(it);
tree[u].num += tree[it].num;
}
}
int iSA[MAXN], SA[MAXN];
int cnt[MAXN], next_gen[MAXN], lcp[ MAXN ], LCP[MAXN][22]; //internal
bool bh[MAXN], b2h[MAXN],m_arr[MAXN];
bool smaller_first_char(int a, int b){
return s[a] < s[b];
}
void SuffixSort(int n) {
for (int i=0; i= 0){
int head = iSA[s];
iSA[s] = head + cnt[head]++;
b2h[iSA[s]] = true;
}
}
for (int j = i; j < next_gen[i]; ++j){
int s = SA[j] - h;
if (s >= 0 && b2h[iSA[s]]){
for (int k = iSA[s]+1; !bh[k] && b2h[k]; k++) b2h[k] = false;
}
}
}
for (int i=0; i
void InitLCP(int n) {
for (int i=0; i 0) {
int j = SA[iSA[i]-1];
while (i + h < n && j + h < n && s[i+h] == s[j+h])
h++;
lcp[iSA[i]] = h;
if (h > 0)
h--;
}
}
}
void ConstructLCP() {
InitLCP( len );
for(int i = 0;i
int GetLCP(int x, int y) {
if(x == y) return len-SA[x];
if(x > y) swap(x,y);
int log = 0;
while((1<
Functional Palindromes
You are viewing a single comment's thread. Return to all comments →
c++
include
// #include "testlib.h" using namespace std ;
define ft first
define sd second
define pb push_back
define all(x) x.begin(),x.end()
define ll long long int
define vi vector
define vii vector >
define pii pair
define plii pair, int>
define piii pair
define viii vector >
define vl vector
define vll vector >
define pll pair
define pli pair
define mp make_pair
define ms(x, v) memset(x, v, sizeof x)
define sc1(x) scanf("%d",&x)
define sc2(x,y) scanf("%d%d",&x,&y)
define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
define scll1(x) scanf("%lld",&x)
define scll2(x,y) scanf("%lld%lld",&x,&y)
define scll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
define pr1(x) printf("%d\n",x)
define pr2(x,y) printf("%d %d\n",x,y)
define pr3(x,y,z) printf("%d %d %d\n",x,y,z)
define prll1(x) printf("%lld\n",x)
define prll2(x,y) printf("%lld %lld\n",x,y)
define prll3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
define pr_vec(v) for(int i=0;i
define f_in(st) freopen(st,"r",stdin)
define f_out(st) freopen(st,"w",stdout)
define fr(i, a, b) for(i=a; i<=b; i++)
define fb(i, a, b) for(i=a; i>=b; i--)
define ASST(x, l, r) assert( x <= r && x >= l )
include
includeconst int MAXN = 105000;
struct node { int next[26]; int len; int sufflink; int num, l, r; };
int len; char s[MAXN]; node tree[MAXN]; int num; // node 1 - root with len -1, node 2 - root with len 0 int suff; // max suffix palindrome long long ans; vi adj[ MAXN ]; viii A; int n, q; bool addLetter(int pos) { int cur = suff, curlen = 0; int let = s[pos] - 'a';
}
void initTree() { num = 2; suff = 2; tree[1].len = -1; tree[1].sufflink = 1; tree[2].len = 0; tree[2].sufflink = 1; tree[1].num = tree[2].num = 0; }
void dfs( int u ) { for( auto it: adj[u] ) { dfs(it); tree[u].num += tree[it].num; } }
int iSA[MAXN], SA[MAXN]; int cnt[MAXN], next_gen[MAXN], lcp[ MAXN ], LCP[MAXN][22]; //internal bool bh[MAXN], b2h[MAXN],m_arr[MAXN];
bool smaller_first_char(int a, int b){ return s[a] < s[b]; }
void SuffixSort(int n) { for (int i=0; i= 0){ int head = iSA[s]; iSA[s] = head + cnt[head]++; b2h[iSA[s]] = true; } } for (int j = i; j < next_gen[i]; ++j){ int s = SA[j] - h; if (s >= 0 && b2h[iSA[s]]){ for (int k = iSA[s]+1; !bh[k] && b2h[k]; k++) b2h[k] = false; } } } for (int i=0; i
void InitLCP(int n) { for (int i=0; i 0) { int j = SA[iSA[i]-1]; while (i + h < n && j + h < n && s[i+h] == s[j+h]) h++; lcp[iSA[i]] = h; if (h > 0) h--; } } }
void ConstructLCP() { InitLCP( len ); for(int i = 0;i
int GetLCP(int x, int y) { if(x == y) return len-SA[x]; if(x > y) swap(x,y); int log = 0; while((1<
bool cmp(const piii &a, const piii &b) { int l1, r1, l2, r2, len1, len2; l1 = a.ft.ft; r1 = a.ft.sd; l2 = b.ft.ft; r2 = b.ft.sd; len1 = r1 - l1 + 1; len2 = r2 - l2 + 1; int res = 0; int v = GetLCP(iSA[l1], iSA[l2]); if(v >= min(len1, len2)) { res = (len1 < len2); } else { res = (iSA[l1] < iSA[l2]); } return res; }
int P[MAXN], HashF[MAXN], HashR[MAXN]; class RollingHash { public: RollingHash() { prime = 100001; mod1 = 1000000007; mod2 = 1897266401; P[0] = 1; for(int i=1; i
};
int main() {
}