先看成一条链

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=; int a[N<<],s[N<<]; int main()
{
freopen("a.in","r",stdin);freopen("a.out","w",stdout);
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d",&a[i]),a[n+i]=a[i];
for (int i=;i<=n*;i++)
{
if (i==cnt+n)
break;
s[i]=s[i-]+a[i]-;
while (s[i]<s[cnt-])
cnt++;
}
LL ans=;
int l=cnt+n-,r=cnt+n-;
while (r>=cnt)
{
while (!a[l])
l--;
ans+=(LL)(r-l)*(r-l);
a[l]--;
r--;
}
printf("%lld\n",ans);
return ;
}

最新文章

  1. SDUTOJ 3312
  2. 【ros】.bag文件
  3. Asp.net把UTF-8编码转换为GB2312编码
  4. 关于&lt;%@ include file=&quot; &quot; %&gt;与&lt;jsp:include page=&quot;&quot;&gt;&lt;/jsp:include&gt;中的那些问题?
  5. web登录与授权
  6. 《ECMAScript标准入门》第二版读书笔记
  7. 深入理解CSS盒模型
  8. Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
  9. 数据处理框架:Pig
  10. 最火移动端跨平台方案盘点:React Native、weex、Flutter
  11. 操作dom获取datatable中的某一行的某一列的数据
  12. 从数据库取出两个同样的字符串用equals比较返回false
  13. re正则模块(二十五)
  14. (转)C# Textbox的ImeMode取值对中文输入法的影响
  15. UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
  16. vue-cli构建项目 npm run build后应该怎么运行在本地查看效果
  17. jQuery的安装
  18. BZOJ4813 CQOI2017小Q的棋盘(树形dp)
  19. 【Python学习笔记】异常处理try-except
  20. Java IO输入输出流 FileWriter 字符流

热门文章

  1. Android 控件布局常用的属性
  2. vue 组件用法
  3. 笔试算法题(03):最小第K个数 &amp; 判定BST后序序列
  4. MTK平台如何定位显示花屏和界面错乱等绘制异常的问题?
  5. CentOS 6.4 下用ntfs-3g挂载Windows NTFS分区
  6. 2018/3/4 Activiti教程之流程部署篇(与Springboot整合版)二
  7. 【NOIP2017】
  8. 安装adt-bundle-windows-x86-20130917时遇到的问题及解决方法
  9. spring-kafka
  10. jupyter-notebook添加python虚拟环境的kernel