D求调
  • 板块学术版
  • 楼主wo_hen_la
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/17 22:20
  • 上次更新2024/8/17 23:33:01
查看原帖
D求调
794701
wo_hen_la楼主2024/8/17 22:20

WA*13

#include <bits/stdc++.h>
using namespace std;

#define sp putchar(' ')
#define en putchar('\n')
#define pb push_back
#define int long long
#define P 998244353
#define HP 1000000000000002097
#define N (int)(4e5+5)

int read(){ char ch=getchar();int x=0,f=1;while(ch>'9' || ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f; }
void print(int x){ if(x<0) putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+'0'); }

int n,m;
int a[N],sum[N];
unordered_map<int,int> mp;
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>n>>m;
	int cnt=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];a[i+n]=a[i];
	}
	sum[0]=0;
	int ans=0;
	mp[0]++;
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
		ans+=mp[sum[i]%m];
		mp[sum[i]%m]++;
		if(i==n) mp[0]--;
	}
	//cout<<ans;
	//mp[0]--;
//	cout<<ans<<" ";
	mp[sum[n]%m]--; 
	for(int i=n+1;i<2*n;i++){
		mp[sum[i-n]%m]--;
		sum[i]=sum[i-1]+a[i];
		//cout<<sum[i]<<" "<<mp[sum[i]%m]<<"\n";
		ans+=mp[sum[i]%m];
		//cout<<ans<<" "<<sum[i]%m<<"\n";
	}
	cout<<ans;
	return 0;
}



2024/8/17 22:20
加载中...