-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromictree.cpp
More file actions
60 lines (49 loc) · 934 Bytes
/
Copy pathpalindromictree.cpp
File metadata and controls
60 lines (49 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#define f first
#define s second
typedef long long ll;
typedef long double ld;
using namespace std;
template<int N>
struct Palindromic {
// palindromic tree
// O(n)
struct node {
map<char, int> children;
int suffix_link = 0;
node() {}
node(int _s) {
suffix_link = _s;
}
};
char s[N];
node nodes[N];
int n, avail, cur;
int imag = 0, real = 1;
Palindromic() {init();}
void init() {
fill(s, s + N, 0);
nodes[imag] = node(imag); // len = -1 (imaginary)
nodes[real] = node(imag); // len = 0
n = 0;
avail = 2;
cur = 0;
}
void add_char(char ch) {
s[n++] = ch;
}
void build_from(const string &a) {
for (char ch : a)
add_char(ch);
}
void build_from(int *a, int n) {
for (int i = 0; i < n; i++) {
add_char(a[i]);
}
}
};
Palindromic<100> p;
int main() {
cout << p.ptr << endl;
return 0;
}