sequence|sequence.in|sequence.out

题目描述:

给定一个整数K和长为N的数列{Ai},求有多少个子串(不含空串)的和为K的倍数。(在这里子串表示{A[i]..A[j]},i<=j)

输入格式:

共两行

第一行两个整数N,K

第二行N个整数表示数列{Ai}

输出格式:

一行一个整数表示满足条件的子串的个数

样例输入:

6
3

1
2 6 3 7 4

样例输出:

7

数据范围:

20%
N<=100

对另外20%
K<=100

对所有数据N<=500000
K<=500000

保证输入数据中所有数都能用longint保存

一定注意mod为负数的情况。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define PROB "sequence"
#define MAXN 550000
#ifdef unix
#define LL "%lld"
#else
#define LL "I64d"
#endif
typedef long long qword;
int num[MAXN];
int sum[MAXN];
int tot[MAXN];
int main()
{
        freopen(PROB".in","r",stdin);
        freopen(PROB".out","w",stdout);
        int n,m;
        int i,j;
        scanf("%d%d",&n,&m);
        for (i=1;i<=n;i++)
        {
                scanf("%d",num+i);
                sum[i]=(sum[i-1]+num[i])%m;
                sum[i]=(sum[i]+m)%m;
        }
        qword ans=0;
        for (i=0;i<=n;i++)
        {
                ans+=tot[sum[i]];
                tot[sum[i]]++;
        }
        printf(LL"\n",ans);
}

Contest20140710 sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. keepalive support-----Programming applications

    TCP Keepalive HOWTO Prev   Next 4. Programming applications This section deals with programming code ...

  2. 使用CSS的类名交集复合选择器

    首先先看一下基本定义: 复合选择器就是两个或多个基本选择器,通过不同方式连接而成的选择器,主要包括“交集”选择器.“并集”选择器.“后代”选择器. 交集选择器 “交集”复合选择器是由两个选择器直接连接 ...

  3. iOS UIKit:animation

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...

  4. 禁止输出重定向(>)覆盖已存在文件(防止误操作)

    在输出重定向中,>表示重定向并覆盖已有文件内容,为了防止误操作,覆盖重要的内容,可以使用如下命令: set -C 这样输出重定向到一个已有文件就会提示: cannot overwrite exi ...

  5. HTML5 Canvas 2D绘图

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/4851774. ...

  6. Big Data應用:以"玩家意見"之數據分析來探討何謂"健康型線上遊戲"(上)

    首先,所有資料都可以從網路上找到,只是我做了一些分析與整理而已.純粹分享心得~~ 最近再做研究的時候我跟我的同事K先生在某次偶然的討論中發現了一件有趣的事情. [疑~~~~~~~新楓之谷的玩家人氣指數 ...

  7. CI 笔记 数据库

    demo: 1.  建立数据库,driver, 字段 name,telphone,idcard,car,content 2. 建立model,Driver_model.php文件, 建立add方法, ...

  8. 忘记Mysql的root密码怎么办?

    解决方法: 1.打开cmd,用net start命令查看是否开启了mysql服务,如果开启,用net stop mysql 命令关闭mysql 2.进入mysql的安装目录下的bin目录,例如:E:\ ...

  9. MVVM模式应用 之为ApplicationBarIconButton 添加Command操作属性

    在学习MVVM的过程中,总是会遇到挫折,一碰到就是花费好长时间去解决..唉,不求量,只求质. 第一种(已经实践成功): (1)http://bindableapplicationb.codeplex. ...

  10. Android学习2--项目文件列表简单分析

    使用Eclipse创建的默认项目文件列表如下: src:src目录是Android工程的源程序目录,该目录用于存放Java项目的源代码 gen:gen目录存放所有自动生成的文件,在这个目录中最关键的文 ...