标签:
先看成一条链
for一遍找位置
在for一遍算答案
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 100010
int n;
int cnt=1;
int a[N<<2],s[N<<2];
int main()
{
freopen("a.in","r",stdin);freopen("a.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]),a[n+i]=a[i];
for (int i=1;i<=n*2;i++)
{
if (i==cnt+n)
break;
s[i]=s[i-1]+a[i]-1;
while (s[i]<s[cnt-1])
cnt++;
}
LL ans=0;
int l=cnt+n-1,r=cnt+n-1;
while (r>=cnt)
{
while (!a[l])
l--;
ans+=(LL)(r-l)*(r-l);
a[l]--;
r--;
}
printf("%lld\n",ans);
return 0;
}
【bzoj4412】[Usaco2016 Feb]Circular Barn
标签:
原文地址:http://www.cnblogs.com/yangjiyuan/p/5324248.html