标签:class turn line www target pos inline for ++
思路同k倍区间。
前缀积得到每个点的正负。枚举右端点\(r\),统计满足\(s[r]\)和\(s[l-1]\)同号的左端点\(l\)的数目,\(s[r]\)和\(s[l-1]\)同号则\(s[l \sim r]\)为正。\(s[l \sim r]\)为负的区间数量同理。
const int N=2e5+10;
int a[N];
int n;
int main()
{
cin>>n;
for (int i = 0; i < n; i ++ ) cin>>a[i];
int pos=1,neg=0;
int s=1;
LL res1=0,res2=0;
for(int i=0;i<n;i++)
{
if(a[i] < 0) s=-s;
if(s > 0)
{
res1+=neg;
res2+=pos;
pos++;
}
else
{
res1+=pos;
res2+=neg;
neg++;
}
}
cout << res1 <<‘ ‘<< res2 <<endl;
//system("pause");
return 0;
}
标签:class turn line www target pos inline for ++
原文地址:https://www.cnblogs.com/fxh0707/p/14817384.html