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. N!末尾有多少个零

    题目一:210!最后结果有几个零. 请自己思索10分钟以上再看解释 凡是这种题目必有规律可言, 关键是你找到这个规律的恒心.可采用笨拙的方法思考. 1!  =  1                   ...

  2. Day02 - Python 基本数据类型

    1 基本数据类型 Python有五个标准的数据类型: Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 1.1 数字 数字数据类型用于 ...

  3. log4j的properties详细配置,分级输出日志文件

            log4j是很常用的日志类包,在此做一下配置的记录 加载jar包和properities配置文件             将commons-logging.jar和logging-lo ...

  4. SqlServer 三级联动、递归表

    SqlServer 省市县三级联动 三张表递归合并成一张表sql如下: insert into table2(area_name,area_parent_id) select province,'0' ...

  5. WisDom.Net 框架设计(五) 权限设计

    WisDom.Net --权限设计 1.需求分析     基本在所有的管理系统中都离不开权限管理.可以这么说,权限管理是管理系统的核心所在. 权限管理说白一些就是每个人能够做什么,不能够做什么.可以说 ...

  6. Asp.Net Mvc4 Ajax提交数据成功弹框后跳转页面

    1.cshtml页面代码 @model Model.UserInfo @{     ViewBag.Title = "Edit"; var options = new AjaxOp ...

  7. Hadoop_Block的几种状态_DataNode

    在Hadoop 2.0 中HDFS 引入了 append 和 hflush 功能之后, 需要为 数据块增加新的状态 来尽最大可能的保证数据的一致性. 参阅文档: http://files.cnblog ...

  8. 关于shell脚本编程的10个最佳实践

    每一个在UNIX/Linux上工作的程序员可能都擅长shell脚本编程.但大家解决问题的方式却不尽相同,这要取决于对专业知识的掌握程度.使 用命令的种类.看待问题的方式等等.对于那些处在shell脚本 ...

  9. 浏览器兼容问题----Firefox不兼容event的解决方法

    一.event.srcElement:当前事件的源: 在IE下,event对象有srcElement属性,但是没有target属性;Firefox下,event对象有target属性,但是没有srcE ...

  10. C#程序中获取电脑硬件配置信息的一种方法

    本文介绍获取cpu信息和内存信息的方法,根据本文所举例的代码可以举一反三获取更多信息. 获取cpu名称的方法: public string GetCpuInfo() { ManagementObjec ...