306566: CF1215B. The Number of Products
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
The Number of Products
题意翻译
### 题目描述 给出一个由$n$个非零整数构成的序列$a_1,a_2,\dots,a_n$。 你需要计算下列两个值: 1.下标对$(l,r)(l\le r)$使得$a_l*a_{l+1}*\dots*a_r$为负数; 2.下标对$(l,r)(l\le r)$使得$a_l*a_{l+1}*\dots*a_r$为正数; ### 输入格式 第一行包含一个整数$n(1\le n\le2*10^5)$,表示序列的元素个数。 第二行包含$n$个非零整数$a_i(-10^9\le a_i\le10^9;a_i\neq 0)$,表示数列中的各个元素。 ### 输出格式 输出两个整数,分别表示乘积为负的子区间个数和乘积为正的子区间个数。题目描述
You are given a sequence $ a_1, a_2, \dots, a_n $ consisting of $ n $ non-zero integers (i.e. $ a_i \ne 0 $ ). You have to calculate two following values: 1. the number of pairs of indices $ (l, r) $ $ (l \le r) $ such that $ a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r $ is negative; 2. the number of pairs of indices $ (l, r) $ $ (l \le r) $ such that $ a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r $ is positive;输入输出格式
输入格式
The first line contains one integer $ n $ $ (1 \le n \le 2 \cdot 10^{5}) $ — the number of elements in the sequence. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ $ (-10^{9} \le a_i \le 10^{9}; a_i \neq 0) $ — the elements of the sequence.
输出格式
Print two integers — the number of subsegments with negative product and the number of subsegments with positive product, respectively.
输入输出样例
输入样例 #1
5
5 -3 3 -1 1
输出样例 #1
8 7
输入样例 #2
10
4 2 -4 3 1 2 -4 3 2 3
输出样例 #2
28 27
输入样例 #3
5
-1 -2 -3 -4 -5
输出样例 #3
9 6