Light oj 1134 - Be Efficient
来源:互联网 发布:java jdk中文文档 编辑:程序博客网 时间:2024/06/06 11:41
题目链接:http://lightoj.com/volume_showproblem.php?problem=1134
You are given an array with N integers, and another integer M. You have to find the number of consecutive subsequences which are divisible by M.
For example, let N = 4, the array contains {2, 1, 4, 3} and M = 4.
The consecutive subsequences are {2}, {2 1}, {2 1 4}, {2 1 4 3}, {1}, {1 4}, {1 4 3}, {4}, {4 3} and {3}. Of these 10 'consecutive subsequences', only two of them adds up to a figure that is a multiple of 4 - {1 4 3} and {4}.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case contains two integers N (1 ≤ N ≤ 105) and M (1 ≤ M ≤ 105). The next line contains N space separated integers forming the array. Each of these integers will lie in the range [1, 105].
Output
For each case, print the case number and the total number of consecutive subsequences that are divisible by M.
Sample Input
Output for Sample Input
2
4 4
2 1 4 3
6 3
1 2 3 4 5 6
Case 1: 2
Case 2: 11
Note
Dataset is huge. Use faster i/o methods.
题目大意:求是m的倍数并且连续的子序列的个数
解析:根据前缀和求
代码如下:
#include<iostream>#include<algorithm>#include<map>#include<stack>#include<queue>#include<set>#include<string>#include<cstdio>#include<cstring>#include<cctype>#include<cmath>#define N 100009using namespace std;const int inf = 0x3f3f3f3f;const int mod = 1e9 + 7;const double eps = 1e-8;const double pi = acos(-1.0);typedef long long LL;int a[N], s[N];int main(){ int t, cnt = 0; int i, num; cin >> t; while(t--) { memset(s, 0, sizeof(s)); int n, m; scanf("%d%d", &n, &m); a[0] = 0; for(i = 1; i <= n; i++) { scanf("%d", &num); a[i] = (a[i - 1] + num) % m; s[a[i]]++; } LL ans = 0; for(i = 0; i < m; i++) ans += (LL)s[i] * ((LL)s[i] - 1LL) / 2LL; printf("Case %d: %lld\n", ++cnt, ans + s[0]); } return 0;}
- Light oj 1134 - Be Efficient
- Light oj 1134 - Be Efficient(dp)
- Light OJ 1134 Be Efficient(水题)
- Light oj 1054 - Efficient Pseudo Code
- Light OJ 1054 - Efficient Pseudo Code
- LightOJ - 1134 Be Efficient
- lightoj 1134 - Be Efficient
- lightoj-1134-Be Efficient
- LightOJ - 1134 Be Efficient(DP)
- light oj 1134
- lightoj 1134 - Be Efficient DP 思路
- Light OJ 1054 Efficient Pseudo Code 求n^m的约数和
- light oj
- light oj
- Light OJ
- Light OJ
- lightoj1134 Be Efficient
- Light OJ 1000
- Xcode插件的删除和更新
- Malicious Outlook Rules
- ubuntu /var/log/下文件介绍
- Servlet入门笔记
- hadoop-2.X HA的基本原理
- Light oj 1134 - Be Efficient
- oracle创建表空间并用数据泵导入数据步骤
- POJ 3222 Matrix Power Series 【等比矩阵前n项之和(性质 OR 二分?)】
- 纪念一下
- (java)快速排序算法
- 这是一个博客的HelloWorld
- 2016湖南省省赛A-2016(CSU1803)
- js日期时间API
- Intellij idea快捷键备忘