Contest20140710 sequence
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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- MapReduce中的Join算法
在关系型数据库中Join是非常常见的操作,各种优化手段已经到了极致.在海量数据的环境下,不可避免的也会碰到这种类型的需求,例如在数据分析时需要从不同的数据源中获取数据.不同于传统的单机模式,在分布式存 ...
- WPF组件开发之组件的基类
之前在网上看到很多关于组件开发的资料,但真正可以用到框架内的却很少.今天贴出自己做的组件,并适合大部分框架的代码. 组件开发需要先做出组件的基类,然后由其他的各类组件去继承这个基类,下面是组件基类的代 ...
- Linux网络相关命令小结
# ifconfig # ifup/ifdown # route -n # ip link show //显示本机所有接口信息 # traceroute # netstat //查看本机网络连接与后门 ...
- Linux下Tomcat安装、配置
/etc/profile./etc/profile.d和.bash_profile区别 /etc/profile和/etc/profile.d区别 .bash_profile 是存放用户的全局变量 / ...
- ANDROID 通过监听来电去电,并弹出悬浮窗
要监听android打电话和接电话,有一种的是通过新建一个Receiver继承自BroadcastReceiver. 还有一种也可通过PhoneStateListener来实现.今天就说说后面一种,废 ...
- DataDictionaryTool 一款生成数据库字典工具支持mysql和oracle
因为常常查看mysql数据结构,频繁操作.很不爽,于是想把数据表制作成数据字典,于是网上搜的一款工具 DataDictionaryTool ,最终制作成功,分享给大家! 1,此工具需要安装jre ,简 ...
- CenOs安装中文输入法
http://jingyan.baidu.com/album/d8072ac4434666ec95cefda1.html?picindex=2 查看链接
- U3D 精灵的点击监听
U3D游戏中,可能会用到点击对象,完成某项操作, 方法一:可以通过接收Input对象的输入,进行利用 方法二:给对象绑定一个collier 组件,然后就能后使用内置方法 这里有点不同,方法一,是不管哪 ...
- setTimeout 和 setInterval区别
setTimeout和setIntelval都有定时的功能!!!取消定时功能的时候,都有对应的clearTimeout以及clearInterval与之对应. 但是他们之间是有区别的! setTime ...
- AIX filesystemcache引发的Oracle事故
链接地址: http://www.jydba.net/aix-filesystemcache%e5%bc%95%e5%8f%91%e7%9a%84oracle%e4%ba%8b%e6%95%85/ A ...