Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize("03")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- #include <queue>
- #include <deque>
- #include <cmath>
- #include <numeric>
- #include <algorithm>
- #include <ctime>
- #include <chrono>
- #include <random>
- #include <functional>
- using namespace std;
- const int MOD = 1e9 + 7;
- const int xx = 257;
- vector<long long> x = {1};
- bool isequal(int from1, int from2, int len, vector<long long> h, vector<long long> x, vector<long long> h2) {
- return (h[from1 + len - 1] + h2[from2 - 1] * x[len]) % MOD ==
- (h2[from2 + len - 1] + h[from1 - 1] * x[len]) % MOD;
- }
- void make_x_koefs(int n) {
- int k = x.size();
- if (n + 1 > k) {
- x.resize(n + 1);
- }
- for (int i = k; i < n + 1; i++) {
- x[i] = (x[i - 1] * xx) % MOD;
- }
- }
- vector <long long> make_polynom(string s) {
- vector <long long> h(s.size(), 0);
- for (int i = 1; i < s.size(); i++) {
- h[i] = (h[i - 1] * xx + s[i]) % MOD;
- }
- return h;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- /*cout << setprecision(x)*/
- cout << fixed;
- string a = " abvsdsf";
- string b = " sds";
- make_x_koefs(a.size());
- vector<long long> h = make_polynom(a);
- vector<long long> h2 = make_polynom(b);
- for (int i = 1; i <= a.size() - b.size() + 1; i++) {
- cout << isequal(i, 1, b.size() - 1, h, x, h2) << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement