链接:

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;
}

最新文章

  1. js/javascript代码注释规范与示例
  2. html5之canvas画图基础
  3. OPENGL若干重要基础概念
  4. phpMailer在thinkPHP框架中邮件发送
  5. 【BZOJ】2237: [NCPC2009]Flight Planning
  6. Java List 如何传值
  7. (委托事件处理)关于多线程执行显示进度条的实例(转)&amp;&amp;线程间操作无效: 从不是创建控件“rtxtEntryNO”的线程访问它。
  8. Skyline中使用AxTE3DWindowEx打开新的一个球体
  9. .htaccess和license文件编写
  10. ThinkPHP中对系统常量的使用
  11. Android艺术开发探索第四章——View的工作原理(下)
  12. Java异常处理-----自行处理
  13. css3图片垂直居中
  14. python插入记录后取得主键id的方法(cursor.lastrowid和conn.insert_id())
  15. 3.《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——检查文件
  16. octave基本指令4
  17. LL(1)文法分析表的构造和分析过程示例
  18. MySQL 跨库主从
  19. 【HDOJ1043】【康拓展开+BFS】
  20. Warning:Configuration &#39;compile&#39; is obsolete and has been replaced with &#39;implementation&#39;. It will be

热门文章

  1. redis事务、并发及应用场景
  2. Redis 常用命令学四:有序集合类型命令
  3. Linux精简版系统安装网络配置问题解决
  4. Linux下安装redis 3.0及C语言中客户端实现demo
  5. JSON文件转为Excel
  6. go 构造切片slice
  7. vue.js移动端app:初始配置
  8. k8s系列0--Kubernetes基础知识
  9. MySQL 多列排序
  10. jacascript Date 学习