Gym 100247C Victor's Research(有多少区间之和为S)
https://vjudge.net/problem/Gym-100247C
题意:
给出一串数,求有多少个区间的和正好等于S。
思路:
计算处前缀和,并且用map维护一下每个前缀和出现的次数。这样接下来枚举左端点即可,确定了左端点,就可以得出右端点的前缀和应该为多少。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = +;
typedef long long ll; int n;
ll s, a[maxn], sum[maxn];
map<ll,int> mp; int main()
{
//freopen("in.txt","r",stdin);
sum[] = ;
mp.clear();
scanf("%d%lld",&n,&s);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
sum[i] = sum[i-]+a[i];
mp[sum[i]]++;
}
ll ans = ;
for(int i=;i<=n;i++)
{
ans += mp[s+sum[i-]];
mp[sum[i]]--;
}
printf("%lld\n",ans);
return ;
}
Gym 100247C Victor's Research(有多少区间之和为S)的更多相关文章
- HLJU 1223: 寻找区间和 (交替推进法)
1223: 寻找区间和 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 13 Solved: 4 [Submit][Status][pid=1223& ...
- [LeetCode] Largest Sum of Averages 最大的平均数之和
We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the su ...
- HDU 5273 区间DP
输入一组数,m次询问 问每一个询问区间的逆序数有多少 区间DP简单题 #include "stdio.h" #include "string.h" int dp ...
- Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数
题面 题意:1e6的数组(1<a[i]<1e6), mul (l,r) =l × (l+1) ×...× r, fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...
- 区间DP 学习笔记
前言:本人是个DP蒟蒻,一直以来都特别害怕DP,终于鼓起勇气做了几道DP题,发现也没想象中的那么难?(又要被DP大神吊打了呜呜呜. ----------------------- 首先,区间DP是什么 ...
- [火星补锅] 非确定性有穷状态决策自动机练习题Vol.1 T3 第K大区间 题解
前言: 老火星人了 解析: 很妙的二分题.如果没想到二分答案.. 很容易想到尝试用双指针扫一下,看看能不能统计答案. 首先,tail指针右移时很好处理,因为tail指针右移对区间最大值的影响之可能作用 ...
- 模拟赛1030d1
[问题描述]从1− ?中找一些数乘起来使得答案是一个完全平方数,求这个完全平方数最大可能是多少.[输入格式]第一行一个数字?.[输出格式]一行一个整数代表答案对100000007取模之后的答案.[样例 ...
- 51nod百度之星2016练习赛
今天看了看51nod发现有这样一个练习赛,就做了做.因为实力太弱想不出E题,各位神犇勿D. (5.26UPD:E题想粗来了) A 区间交 不难发现若干线段[li,ri]的交就是[max(li),min ...
- hdu 6058---Kanade's sum(链表)
题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...
随机推荐
- php小数加减精度问题,比特币计算精度问题
php小数加减精度问题,比特币计算精度问题 在php开发时,有小数加减的场景.结果发现不能够等于预想的值,bccomp比较二个高精确度数字.语法: int bccomp(string left ope ...
- Caterpillar sis service information training and software
Cat et sis caterpillar heavy duty truck diagnostics repair. Training demonstration allows.cat electr ...
- 使用BenchmarkSQL测试PostgreSQL
BenchmarkSQL是一款经典的开源数据库测试工具,内嵌了TPCC测试脚本,可以对EnterpriseDB.PostgreSQL.MySQL.Oracle以及SQL Server等数据库直接进行测 ...
- storm的trident编程模型
storm的基本概念别人总结的, https://blog.csdn.net/pickinfo/article/details/50488226 编程模型最关键最难就是实现局部聚合的业务逻辑聚合类实现 ...
- c#md5加密的简单用法
using System.Security.Cryptography; //MD5 md5 = MD5.Create(); MD5 md5 = new MD5CryptoServiceProvider ...
- IntelliJ IDEA. Debug模式
资料收集: https://www.bilibili.com/video/av6749471/?p=16 eclipse debug模式. 基础 Intellij Idea--Debug使用 Inte ...
- java.lang.IllegalStateException: Failed to check the status of the service
java.lang.IllegalStateException: Failed to check the status of the service com.pinyougou.sellergoods ...
- fjwc2019 D1T2 原样输出(后缀自动机+dp)
#179. 「2019冬令营提高组」原样输出 暴力对每个串建后缀自动机,然后暴力枚举每个自动机的子串.可以拿到部分分. 然鹅我们可以把每个后缀自动机连起来. 我们知道,后缀自动机是用最少的点(空间)表 ...
- gdb调试程序函数名为问号,什么原因?step by step解决方案
gdb调试程序函数名为问号,什么原因? http://bbs.chinaunix.net/thread-1823649-1-1.html http://www.bubuko.com/infodetai ...
- 3 字节的 UTF-8 序列的字节 3 无效 解决
参考下列应该可以解决,笔者为3. 1.https://blog.csdn.net/hostel_2/article/details/51517361 2.https://blog.csdn.net/u ...