Skip to content
Snippets Groups Projects
Commit 43eb105f authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Small fixes

parent a6251d32
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
/// Include: /// Include:
/// - structure/disjoint_set /// - structure/disjoint_set
typedef pair<ii,int> iii; using edge = pair<ii,int>;
vector<iii> edges; vector<edge> edges;
struct Kruskal { struct Kruskal {
int N; int N;
...@@ -17,8 +17,8 @@ struct Kruskal { ...@@ -17,8 +17,8 @@ struct Kruskal {
// Minimum Spanning Tree: comp = less<int>() // Minimum Spanning Tree: comp = less<int>()
// Maximum Spanning Tree: comp = greater<int>() // Maximum Spanning Tree: comp = greater<int>()
int run(vector<iii> &mst, function<bool(int,int)> comp) { int run(vector<edge> &mst, function<bool(int,int)> comp) {
sort(all(edges), [&](const iii &a, const iii &b) { sort(all(edges), [&](const edge &a, const edge &b) {
return comp(a.se, b.se); return comp(a.se, b.se);
}); });
......
...@@ -9,36 +9,33 @@ ...@@ -9,36 +9,33 @@
struct KMP { struct KMP {
string patt; string patt;
vector<int> table; vector<int> pi;
KMP(string patt) : KMP(string patt) :
patt(patt), table(patt.size()+1) patt(patt), pi(patt.size())
{ preprocess(); } { preprocess(); }
void preprocess() { void preprocess() {
fill(all(table), -1); patt[0] = 0;
for (int i = 1, j = 0; i < patt.size(); ++i) {
while (j > 0 && patt[i] != patt[j])
j = pi[j - 1];
for (int i = 0, j = -1; i < patt.size(); ++i) { if (patt[i] == patt[j]) j++;
while (j >= 0 && patt[i] != patt[j]) pi[i] = j;
j = table[j];
table[i + 1] = ++j;
} }
} }
vector<int> search(const string &txt) { void search(const string &txt) {
vector<int> occurs;
for (int i = 0, j = 0; i < txt.size(); ++i) { for (int i = 0, j = 0; i < txt.size(); ++i) {
while (j >= 0 && txt[i] != patt[j]) while (j > 0 && txt[i] != patt[j])
j = table[j]; j = pi[j - 1];
j++;
if (txt[i] == patt[j]) j++;
if (j == patt.size()) { if (j == patt.size()) {
occurs.pb(i - j); cout << "Pattern found at " << (i - j) << ende;
j = table[j]; j = pi[j - 1];
} }
} }
return occurs;
} }
}; };
...@@ -20,7 +20,7 @@ struct SegmentTree { ...@@ -20,7 +20,7 @@ struct SegmentTree {
T ident = T(); T ident = T();
vector<T> tree; vector<T> tree;
SegmentTree(F &func) : func(func), tree(MAX*4) {} SegmentTree(F func) : func(func), tree(MAX*4) {}
void build(const vector<T> &v, void build(const vector<T> &v,
int node = 1, int l = 0, int r = N - 1) int node = 1, int l = 0, int r = N - 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment