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. Windows下Redis的安装使用[转]

    redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  2. javamail发送邮件的简单实例(转)

    今天学习了一下JavaMail,javamail发送邮件确实是一个比较麻烦的问题.为了以后使用方便,自己写了段代码,打成jar包,以方便以后使用.呵呵 注意:要先导入javamail的mail.jar ...

  3. JAVA向文件中追加内容(转)

    向文件尾加入内容有多种方法,常见的方法有两种: RandomAccessFile类可以实现随机访问文件的功能,可以以读写方式打开文件夹的输出流 public void seek(long pos)可以 ...

  4. Btrace是一个实时监控工具

    http://blog.csdn.net/gzh0222/article/details/9731031 Btrace是一个实时监控工具,可以无需修改应用代码(事实上它修改了字节码),来达到不可告人的 ...

  5. WebService学习笔记系列(三)

    网上有一些提供webservice服务的网站,我们要怎么调用呢? 今天来看个如何调用手机归属地查询服务.这个网站上提供了许多webservice服务,其中包括手机归属地查询服务,我们今天就用wsimp ...

  6. Oracle11g新特性导致空表不能导出问题

        ORACLE 11G在用EXP导出时,发现空表(没有数据或者没有用过的表)不能导出了.     查了一下资料,说是Oracle 11G中有个新特性,当表无数据时,不分配segment,以节省空 ...

  7. ubuntu 12.04 编译安装 nginx

    下载源码包 nginx 地址:http://nginx.org/en/download.html 编译前先安装两个包: 直接编译安装会碰到缺少pcre等问题,这时候只要到再安装两个包就ok sudo ...

  8. 让IE支持Css3属性(圆角、阴影、渐变)

    >>>>>>>>>>>>>>>>>>>>>>>>> ...

  9. build/core/config.mk

    # 如果定义了ANDROID_BUILD_SHELL,则ANDROID_BUILD_SHELL # 否则使用默认的/bin/bash ifdef ANDROID_BUILD_SHELL SHELL : ...

  10. [解答]对‘’未定义的引用 collect2: 错误: ld 返回 1

    写的makefile适用于32位,但是放到64位机器上make就有问题. 需要在makefile中gcc -o....的结尾加上-pthread,例如: bloomfilter.o: bloomfil ...