-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumber_Theory_someone.cpp
More file actions
70 lines (70 loc) · 1.38 KB
/
Number_Theory_someone.cpp
File metadata and controls
70 lines (70 loc) · 1.38 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
using namespace std;
int p[15][200005],coun;
int ans[14][200005];
int a[200005];
int b[200005];
int c[15][200005];
int num[15];
int main()
{
int n,m,i,j,k,d=0,ch;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=m;i++)
scanf("%d",&b[i]);
for(i=1,j=1;i<=m;i++,j++)
{
if(b[i]==1)
{
j=0;
coun++;
continue ;
}
c[coun][j]=b[i];
num[coun]++;
}
for(j=0;j<=coun;j++)
{
k=0;
for(i=2;i<=num[j];i++)
{
while(k&&c[j][k+1]!=c[j][i])
k=p[j][k];
if(c[j][k+1]==c[j][i])
k++;
p[j][i]=k;
//printf("%d ",c[j][i]);
}
//printf("\n");
}
for(j=0;j<=coun;j++)
{
k=0;
for(i=1;i<=n;i++)
{
while(k&&a[i]!=c[j][k+1])
k=p[j][k];
if(a[i]==c[j][k+1])
k++;
ans[j][i]=k==num[j];
//printf("%d ",ans[j][i]);
}
//printf("\n");
}
for(i=1;i<=coun;i++){
num[i]+=num[i-1]+1;
}
for(i=1;i+m-1<=n;i++)
{
ch=1;
for(j=0;j<=coun;j++)
if(ans[j][i+num[j]-1]==0)
ch=0;
d+=ch;
//printf(">>%d %d\n",coun,d);
}
printf("%d",d);
return 0;
}