#include "message.h"
#include "poszukiwania.h"
#include <cstdio>
typedef long long LL;
LL n,m;
LL pp,hasz_n,hasz_m,p=1000000007LL,q=3000000019LL;
int res;
int main()
{
if(MyNodeId()==0)
{
pp=p;
m=SignalLength();
n=SeqLength();
if(m>n)
{
printf("0");
return 0;
}
for(LL i=1; i<=n; ++i)
{
hasz_n+=SeqAt(i);
hasz_n*=p;
hasz_n%=q;
if(i<=m)
{
hasz_m+=SignalAt(i);
hasz_m*=p;
hasz_m%=q;
pp*=p;
pp%=q;
}
else
{
hasz_n-=((SeqAt(i-m)*pp)%q);
hasz_n+=q;
hasz_n%=q;
}
if(hasz_n == hasz_m && i>=m)
++res;
}
printf("%d", res);
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include "message.h" #include "poszukiwania.h" #include <cstdio> typedef long long LL; LL n,m; LL pp,hasz_n,hasz_m,p=1000000007LL,q=3000000019LL; int res; int main() { if(MyNodeId()==0) { pp=p; m=SignalLength(); n=SeqLength(); if(m>n) { printf("0"); return 0; } for(LL i=1; i<=n; ++i) { hasz_n+=SeqAt(i); hasz_n*=p; hasz_n%=q; if(i<=m) { hasz_m+=SignalAt(i); hasz_m*=p; hasz_m%=q; pp*=p; pp%=q; } else { hasz_n-=((SeqAt(i-m)*pp)%q); hasz_n+=q; hasz_n%=q; } if(hasz_n == hasz_m && i>=m) ++res; } printf("%d", res); } } |
English