A. 乘积为正

    Type: Default File IO: array 1000ms 256MiB

乘积为正

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

现在给你一个长度为nn的数组。数组中仅包含11和−1-1。

你的任务是求解有多少个连续的子数组的乘积是正的。

输入格式

第一行一个正整数nn,表示数组的长度

接下来一行nn个数字,以空格分开,表示数组中的每个数字。保证是11和−1-1中的一个。

输出格式

一个整数,表示有多少连续的子数组的乘积是正的。

样例 #1

样例输入 #1

5
1 1 -1 -1 1

样例输出 #1

10

样例 1 解释

  • 第1个位置开始的合法数组有:[1], [1, 1], [1, 1, -1, -1], [1, 1, -1, -1, 1]

  • 第2个位置开始的合法数组有:[1], [1, -1, -1], [1, -1, -1, 1]

  • 第3个位置开始的合法数组有:[-1, -1], [-1, -1, 1]

  • 第4个位置开始的合法数组有:

  • 第5个位置开始的合法数组有:[1]

共10个子数组满足要求。

数据范围

共20个测试点,每个测试点5分。

测试点编号 数据范围 特殊性质
#1~#4 1≤n≤501≤n≤50 无
#5 1≤n≤1,0001≤n≤1,000 数组中数字均为1
#6 数组中数字均为-1
#7~#10 无
#11 1≤n≤200,0001≤n≤200,000 数组中数字均为1
#12 数组中数字均为-1
#13~#20 无

大样例输入 大样例输出

20250727 提高组考试

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2025-7-27 8:00
End at
2025-7-27 12:00
Duration
4 hour(s)
Host
Partic.
13