比赛 2026.1.8 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 数字段 最终得分 100
用户昵称 123 运行时间 2.324 s
代码语言 C++ 内存使用 4.21 MiB
提交时间 2026-01-08 20:57:17
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10,M=1e3+10; 
int n,m,k,l,mp[M],a[N],b[M];
long long ret=0,q[N];
void exgcd(long long a,long long b,long long &x,long long &y)
{
	if (b==0)
	{
		x=1,y=0;
		return ;
	}
	exgcd(b,a%b,x,y);
	long long cnt=x;
	x=y,y=cnt-a/b*y;
}
int main() {
	freopen("number.in","r",stdin),freopen("number.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m>>k>>l;
	q[0]=1;
	for (int i=1;i<=n;i++) cin>>a[i],a[i]%=m,q[i]=q[i-1]*a[i];
	long long cnt=1;
	for (int i=1;i<=n;i++)
	{
		if (i>l)
		{
			cnt=cnt*a[i]%m;
			long long x,y;
			exgcd(q[i-l-1],m,x,y);
			x=(x*q[i]%m+m)%m;
			mp[x]--;
//			cout<<x<<endl;
		}
		memset(b,0,sizeof(b));
		for (int j=0;j<m;j++) b[(j*10+a[i])%m]+=mp[j];
		for (int j=0;j<m;j++) mp[j]=b[j],ret+=(j==k ? mp[j] : 0);
		mp[a[i]]++,ret+=(a[i]==k);
//		cout<<ret<<endl;
	} 
	cout<<ret;
	return 0;
}