【题解】CF1426D Non-zero Segments
\(\text{Solution:}\)
若\([l,r]\)子段和是\(0,\)则\(sum[r]=sum[l-1].\)
于是我们可以考虑维护当前哪一个前缀和出现过。对于区间\([l,r]\)若其子段和为\(0\)则在\(r-1\)的地方插入一个\(+\infty\)即可。
初始化要把\(0\)赋值为出现过。
#include<bits/stdc++.h>
using namespace std;
int n,a[500010];
map<long long,bool>mp;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
mp[0]=true;
long long s=0;
int ans=0;
for(int i=1;i<=n;++i){
s+=a[i];
if(mp[s]){
ans++;
mp.clear();
mp[0]=true;
s=a[i];
}
mp[s]=true;
}
cout<<ans<<endl;
return 0;
}
```cpp
【题解】CF1426D Non-zero Segments的更多相关文章
- LeetCode题解之Number of Segments in a String
1.题目描述 2.题目分析 找到字符串中的空格即可 3.代码 int countSegments(string s) { ){ ; } vector<string> v; ; i < ...
- 题解-CF1389F Bicolored Segments
题面 CF1389F Bicolored Segments 给 \(n\) 条线段 \([l_i,r_i]\),每条有个颜色 \(t_i\in\{0,1\}\),求最多选出多少条线段,使没有不同颜色的 ...
- CodeForces 430A Points and Segments (easy)(构造)题解
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序 ...
- PAT甲题题解-1104. Sum of Number Segments (20)-(水题)
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- POJ3304:Segments——题解
http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ——————————————————————— ...
- [CF846C]Four Segments题解
我们暴力枚举一下\(delim_{1}\) 然后对于每个\(delim_{1}\),O(n)扫一遍+前缀和求出最大\(delim_{0}\)和\(delim_{2}\),然后记录一下它们的位置就行啦 ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- usaco training 4.1.3 fence6 题解
Fence Loops题解 The fences that surround Farmer Brown's collection of pastures have gotten out of cont ...
随机推荐
- 3D人物移动控制实现方案
要控制3D人物在3D世界中进行正常的移动.转向,一般有两种情况: 1.使用人物动画控制人物 的移动 转向 2.使用脚本控制人物 的移动.转向 对方案一: Animator 组件勾选上 Apply Ro ...
- Android studio Debug 源码
原来有的地方打不了断点 会提示no executable code at line xxx 源码sdk里有,sdkManager下好对应版本,然后使用对应版本的模拟器debug就行了 如果要debug ...
- webpack使用优化(基本篇
为什么要使用Webpack 与react一类模块化开发的框架搭配着用比较好. 属于配置型的构建工具,比较用容易上手,160行代码可大致实现gulp400行才能实现的功能. webpack使用内存来对构 ...
- 跟着尚硅谷系统学习Docker-【day08】
day08-20200723 p32.docker 安装redis [ docker pull redis] [docker run -p 6397:6397 -v /tmp/mydocker ...
- springboot x.x.x RELEASE不同版本的差异
springboot 1.x.x RELEASE的 application.properties配置 server.context-path=/ server.port=8080 server.ses ...
- ascii unicode utf-8 url编码
ascii 编码 计算机内部,所有信息最终都是一个二进制值 上个世纪60年代,美国制定了一套字符编码ascii ascii 编码就是定义:英语字符与二进制位之间的关系 unixcs unicode编码 ...
- Navicat 闲置时间过长会卡死
前段时间使用navicat连接线上的数据库,Navicat 闲置时间过长会卡死.解决方案:选中数据库,右键点击 编辑连接,修改保持连接间隔为 20秒.非常 so easy ! 1. 选中数据库,右键点 ...
- oracle之二数据库审计
数据库审计audit(PPT-I-320-334) 13.1 审计的功能:监控特定用户在database 的action(操作) 13.2 审计种类: 1)标准数据库审计(语句审计.权限审计.对象审计 ...
- charles常用功能 request和response(简单的操作)
先介绍一个修改request请求参数值的方法吧 第一步: 拷贝完成后还需要配置一下: 先添加一个: 然后下一步: 最后点击OK,就可以开始操作request和response数据了 先修改reques ...
- Bootstrap一周学习小结
一.响应式布局 1.bootstrap是自适应mobile和web,会根据分辨率大小而自适应的一个代码库,Bootstrap定义了很多js和css的效果,把这些效果集成为多个API,供在使用时调用. ...