B4105 [CSP-X2024 山东] 消灭怪兽 题解
FanzhuoOVO · · 题解
题意
就是求武器数组
思路
由于
每次计算前缀和时需要对
最后把
注意!
所以:十年 OI 一场空,____。
Code
#include <iostream>
#define ll long long
using namespace std;
const int M = 1e6 + 5;
ll a[M], e[M], tong[M];
int main()
{
ll n, k, cnt = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
e[i] += (e[i - 1] + a[i]) % k;
}
tong[0] = 1;
for(int i = 1; i <= n; i++)
{
tong[e[i]]++;
}
for(int i = 0; i < k; i++)
{
if(tong[i] >= 2)
{
cnt += tong[i] * (tong[i] - 1) / 2;
}
}
cout << cnt;
return 0;
}