思路:
直接把串复制一遍,然后每次查询连续n个中前缀和最小的减一下就OK
c o d e code code
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n, m, ans;
int f[2000010][32];
int main()
{
scanf("%d", &n);
m=n;
for(register int i=1; i<=n; ++i)
scanf("%d", &f[i][0]), f[i+n][0]=f[i][0];
n*=2;
for(register int i=1; i<=n; ++i)
f[i][0]+=f[i-1][0];
for(register int j=1; j<=log2(n); ++j)
for(register int i=1; i+(1<<j)-1<=n; ++i)
f[i][j]=min(f[i][j-1], f[i+(1<<j-1)][j-1]);
for(register int i=1; i<=m; ++i)
{
register int j=i+m-1;
register int k=log2(m);
ans+=(min(f[i][k], f[j-(1<<k)+1][k])-f[i-1][0]>=0);
}
printf("%d", ans);
return 0;
}