题意:给定 n 个数,和 m,问你是不是存在连续的数和是m的倍数。
析:考虑前缀和,如果有两个前缀和取模m相等,那么就是相等的,一定要注意,如果取模为0,就是真的,不要忘记了,我当时就没记得。。。。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int vis[maxn]; int main(){
// ios::sync_with_stdio(false);
int T, q; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
LL sum = 0;
memset(vis, 0, sizeof(vis));
bool ok = false;
vis[0] = 1;
for(int i = 0; i < n; ++i){
scanf("%d", &q);
sum += q;
if(vis[sum%m]) ok = true;
vis[sum%m] = 1;
}
printf("%s\n", ok ? "YES" : "NO");
}
return 0;
}