Codeforces Round #585 (Div. 2) B. The Number of Products(DP)
链接:
https://codeforces.com/contest/1215/problem/B
题意:
You are given a sequence a1,a2,…,an consisting of n non-zero integers (i.e. ai≠0).
You have to calculate two following values:
the number of pairs of indices (l,r) (l≤r) such that al⋅al+1…ar−1⋅ar is negative;
the number of pairs of indices (l,r) (l≤r) such that al⋅al+1…ar−1⋅ar is positive;
思路:
DP[i][0]为i位置往前连续的负数, DP[i][1] 为偶数.
最后累计一下.
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10;
int a[MAXN];
LL Dp[MAXN][2];
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
if (a[1] > 0)
Dp[1][1] = 1;
else
Dp[1][0] = 1;
for (int i = 2;i <= n;i++)
{
if (a[i] > 0)
{
Dp[i][1]++;
Dp[i][0] += Dp[i-1][0];
Dp[i][1] += Dp[i-1][1];
}
else
{
Dp[i][0]++;
Dp[i][0] += Dp[i-1][1];
Dp[i][1] += Dp[i-1][0];
}
}
LL sum1 = 0, sum2 = 0;
for (int i = 1;i <= n;i++)
sum1 += Dp[i][0], sum2 += Dp[i][1];
cout << sum1 << ' ' << sum2 << endl;
return 0;
}
Codeforces Round #585 (Div. 2) B. The Number of Products(DP)的更多相关文章
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP)
题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP),BZOJ大理石(同一道题)题解
题意 林老师是一位大理石收藏家,他在家里收藏了n块各种颜色的大理石,第i块大理石的颜色为ai.但是林老师觉得这些石头在家里随意摆放太过凌乱,他希望把所有颜色相同的石头放在一起.换句话说,林老师需要对现 ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- Codeforces Round #585 (Div. 2)
https://www.cnblogs.com/31415926535x/p/11553164.html 感觉很硬核啊这场,,越往后越做不动,,,emmmm,,,(这场是奔着最后一题 2sat 来的, ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- Codeforces Round #585 (Div. 2) CF1215A~C
CF1215A. Yellow Cards简单的模拟,给定了黄票张数,判断最少和最多有多少人被罚下场. #include <bits/stdc++.h> using namespace s ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #585 (Div. 2) D. Ticket Game
链接: https://codeforces.com/contest/1215/problem/D 题意: Monocarp and Bicarp live in Berland, where eve ...
随机推荐
- MapReduce的输入文件是两个
[学习笔记] 1.对于MapReduce程序,如何输入文件是两个文件? 这一小节,我们将继续第一章大数据入门的HelloWorld例子做进一步的研究.这里,我们研究如何输入文件是两个文件.packag ...
- 去掉右键Open Folderas Intellij IDEA Project
解决: WIN+R键打开运行,输入regedit 打开注册表 在地址栏输入: 计算机\HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell 然 ...
- TCP状态转换(图解+文字解说)
<深入分析 javaweb 技术内幕>P38 读书扩展 作者:淮左白衣 写于2018年4月12日20:58:36 目录 TCP状态转换图解 图解三次握手 文字讲解三次握手: 图解四次挥手 ...
- 第6章:LeetCode--数组(冒泡排序、快速排序)
11. Container With Most Water class Solution { public: int maxArea(vector<int>& height) { ...
- C#基础算法题 找出最大值和最小值
找出最大值和最小值 题目要求 输入n个数,n<=100,找到其中最小的数和最大的数 实现代码 using System; namespace _1.求最大最小 { class Program { ...
- SAS学习笔记29 logistic回归
变量筛选 当对多个自变量建立logistic回归模型时,并不是每一个自变量对模型都有贡献.通常我们希望所建立的模型将具有统计学意义的自变量都包含在内,而将没有统计学意义的自变量排除在外,即进行变量筛选 ...
- elasticsearch 集群详解
ES为什么要实现集群 在单台ES服务器节点上,随着业务量的发展索引文件慢慢增多,会影响到效率和内存存储问题等. 如果使用ES集群,会将单台服务器节点的索引文件使用分片技术,分布式的存放在多个不同的物理 ...
- C# Entity Framework The ObjectContext instance has been disposed and can no longer be used for operations that require a connection
The ObjectContext instance has been disposed and can no longer be used for operations that require a ...
- poj 3253 哈夫曼贪心
http://poj.org/problem?id=3253 题意: FJ需要修补牧场的围栏,他需要 N 块长度为 Li 的木头(N planks of woods).开始时,FJ只有一块无限长的木板 ...
- Angularjs 中 ng-repeat 循环绑定事件
用ng-repeat循环是如果有ng-click之类的事件需要传入参数我们一般这样写 <span class='del' ng-click="RemoveCost({{item.Id} ...