-
Notifications
You must be signed in to change notification settings - Fork 0
/
manacher.sublime-snippet
86 lines (84 loc) · 1.25 KB
/
manacher.sublime-snippet
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<snippet>
<content><![CDATA[
auto manacherodd=[](string &S)
{
int N=S.length();
vector<pair<int,int>>v;
for(int i=0,l=-1,r=0;i<N;i++)
{
int cl=i,cr=i;
if(i<r)
{
int k=v[l+r-i].second-v[l+r-i].first;
cl-=k/2;
cr+=k/2;
if(cr>r)
{
int x=cr-r;
cr=r;
cl+=x;
}
}
while(cl>=0 && cr<N)
{
if(S[cl]==S[cr])
{
cl--;
cr++;
}
else
break;
}
v.push_back({cl+1,cr-1});
if(cr>r)
{
r=cr;
l=cl;
}
}
return v;
};
auto manachereven=[](string &S)
{
int N=S.length();
vector<pair<int,int>>v;
for(int i=0,l=-1,r=0;i<N-1;i++)
{
int cl=i,cr=i+1;
if(i<r-1)
{
int k=v[l+r-i-1].second-v[l+r-i-1].first;
cl-=k/2;
cr+=k/2;
if(cr>r-1)
{
int x=cr-r+1;
cr=r-1;
cl+=x;
}
}
while(cl>=0 && cr<N)
{
if(S[cl]==S[cr])
{
cl--;
cr++;
}
else
break;
}
v.push_back({cl+1,cr-1});
if(cr>r)
{
r=cr;
l=cl;
}
}
return v;
};
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>manacher</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>