AcWing 3574. 乘积数量
原题链接
中等
作者:
Youbuhua
,
2021-05-26 21:22:49
,
所有人可见
,
阅读 173
#include<bits/stdc++.h>
const int N = 2*1e5+10;
int a[N];
int z[N];
int f[N];
int pre[N];
using namespace std;
int main()
{
int n;
cin >> n;
int temp = 1;
pre[0] = 1;
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
if(a[i] < 0){
a[i] = -1;
}
else{
a[i] = 1;
}
pre[i] = pre[i-1] * a[i];
temp *= a[i];
z[i] = z[i-1];
f[i] = f[i-1];
if(temp > 0){
z[i]++;
}
else{
f[i]++;
}
}
long long ans = 0;
for(int i = 1; i <= n; i++){
if(pre[i] > 0){
ans += z[i-1]+1;
}
else{
ans += f[i-1];
}
}
cout << (long long)n*(n+1)/2-ans << " " << ans << "\n";
return 0;
}