Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int a[100010], sum[100010], cnt[7];
- //cnt[x] 记录到当前位置,前缀和 %7 = x 的有多少个
- signed main () {
- cin >> n;
- cnt[0] = 1;
- int ans = 0;
- for (int i = 1; i <= n; i ++) {
- cin >> a[i];
- sum[i] = sum[i - 1] + a[i];
- ans += cnt[sum[i] % 7]; // 当前位置作为右端点的答案数
- cnt[sum[i] % 7] ++; // 更新cnt , 当前点的贡献
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement