Cod sursa(job #3319075)

Utilizator ioanxhIoan Budeanu ioanxh Data 30 octombrie 2025 14:24:32
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.51 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 setinf(x) memset(x,0x3f3f3f3f,sizeof(x));
#define set0(x) memset(x,0,sizeof(x));
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define DD 100001
#define nl '\n'
using namespace std;
const string file="abc2";
ifstream f(file+".in");
ofstream g(file+".out");
//#define f cin
//#define g cout
string s,t;
map<ll,bool> mp;
const ll mod1=1e9+7,mod2=1e9+9;
const ll b1=131,b2=37;
ll r;
int main(){
    f>>s;
    int l=0;
    while (f>>t) {
        ll h1=0,h2=0;
        for (char c:t) {
            h1=(h1*b1+(c-'a'))%mod1;
            h2=(h2*b2+(c-'a'))%mod2;
        }
        mp[(h1<<32)^h2]=1;
        if (!l) l=t.size();
    }
    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;
}