Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define sz(x) (int)(x.size())
- typedef long long ll;
- const int N = 2e5+5;
- const int mod = 1e9+7;
- const int P = 31;
- string s, t;
- int h[N], p[N], hasht;
- int mul(int a, int b){
- return a*1LL*b % mod;
- }
- int get_hash(int l, int r){
- return (h[r] - h[l-1]*p[r-l+1] + mod*1LL*mod) % mod;
- }
- void solve(){
- cin >> s >> t;
- p[0] = 1;
- for(int i = 1; i <= 2e5; i++)
- p[i] = mul(p[i-1], P);
- for(int i = 1; i <= sz(s); i++){
- h[i] = (h[i-1] + (s[i-1] - 'a' + 1) * p[i-1]) % mod;
- }
- for(int i = 1; i <= sz(t); i++){
- hasht += ((t[i-1] - 'a' + 1) * p[i-1]);
- hasht %= mod;
- }
- for(int i = sz(t); i <= sz(s); i++){
- int l = i-sz(t)+1, r = i;;
- if(get_hash(l, r) == hasht)
- cout << l-1 << ' ';
- }
- }
- signed main(){
- speed;
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement