Cod sursa(job #3319079)

Utilizator ioanxhIoan Budeanu ioanxh Data 30 octombrie 2025 14:36:44
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 kb
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fast ios_base::sync_with_stdio(0);f.tie(0);g.tie(0);
#define ll long long
using namespace std;
const string file="abc2";
ifstream f(file+".in");
ofstream g(file+".out");
//#define f cin
//#define g cout
string s,t;
unordered_map<ll,bool> mp;
const int mod1=1e9+7,mod2=1e9+9;
const int b1=131,b2=37;
int r;
int main(){fast
    f>>s;
    int l=0;
    while (f>>t) {
        ll h1=0,h2=0;
        int n=t.size();
        for (int i=0; i<n; i++) {
            h1=(h1*b1+(t[i]-'a'))%mod1;
            h2=(h2*b2+(t[i]-'a'))%mod2;
        }
        mp[(h1<<32)^h2]=1;
        if (!l) l=n;
    }
    ll p1=1,p2=1;
    ll h1=0,h2=0;
    for (int i=0; i<l; ++i) {
        h1=(h1*b1+(s[i]-'a'))%mod1;
        h2=(h2*b2+(s[i]-'a'))%mod2;
        if (i>0) {
            p1=(p1*b1)%mod1;
            p2=(p2*b2)%mod2;
        }
    }
    if (mp.count((h1<<32)^h2)) ++r;
    for (int i=l; i<s.size(); ++i) {
        h1=(h1-(s[i-l]-'a')*p1%mod1+mod1)%mod1;
        h1=(h1*b1+(s[i]-'a'))%mod1;

        h2=(h2-(s[i-l]-'a')*p2%mod2+mod2)%mod2;
        h2=(h2*b2+(s[i]-'a'))%mod2;

        if (mp.count((h1<<32)^h2)) ++r;
    }
    g<<r;
    // system("pause");
    return 0;
}