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 ...
随机推荐
- WCF学习心得--客户端获取服务端自定义类数据
因项目需求,需要一个WCF服务,赶鸭子上架吧!下面直接切入正题! 首先创建WCF应用程序,具体如何创建就不赘述了,网上一大篇,我主要说说自己遇到的问题 问题一:超时问题,在最后获取数据的时候突然提示服 ...
- Paxos算法之旅(四)zookeeper代码解析--转载
ZooKeeper是近期比较热门的一个类Paxos实现.也是一个逐渐得到广泛应用的开源的分布式锁服务实现.被认为是Chubby的开源版,虽然具体实现有很多差异.ZooKeeper概要的介绍可以看官方文 ...
- value must be omitted for boolean attributes
jsx文件中 html5一些标签的属性是boolean的,<div hidden="true">是不被允许的,要改成<div hidden>或<div ...
- Android Studio中常用插件及浅释
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园:追风917 插件可以来这个仓库查找:Android Studio Plugins 这里给出几个平时常用到的as插 ...
- 分享:Svg文件转换为图片(调用 Inkscape 命令行)
其实只是做了简单封装,可以方便进行批量转换. 获取Svg对象坐标的代码请看:根据svg节点对象类型和路径值转换坐标值, DrawingColor方法是进行颜色填充的. /// <summary& ...
- Stream To String , String To Stream
public static string StreamToString(Stream stream) { stream.Position = 0; using (StreamReader stremR ...
- Angularjs总结(三)摸态框的使用
静态页面: <input class="btn btnStyle " value="提 取" type="button" ng-cli ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- MVVM模式应用 之NotificationObject类
public abstract class NotificationObject : INotifyPropertyChanged { public event PropertyChanged ...
- 深入理解QStateMachine与QEventLoop事件循环的联系与区别
最近一直在倒腾事件循环的东西,通过查看Qt源码多少还是有点心得体会,在这里记录下和大家分享.总之,对于QStateMachine状态机本身来说,需要有QEventLoop::exec()的驱动才能支持 ...