【bzoj4412】[Usaco2016 Feb]Circular Barn
2024-09-30 16:21:15
先看成一条链
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 ;
}
最新文章
- SDUTOJ 3312
- 【ros】.bag文件
- Asp.net把UTF-8编码转换为GB2312编码
- 关于<;%@ include file="; "; %>;与<;jsp:include page=";";>;<;/jsp:include>;中的那些问题?
- web登录与授权
- 《ECMAScript标准入门》第二版读书笔记
- 深入理解CSS盒模型
- Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
- 数据处理框架:Pig
- 最火移动端跨平台方案盘点:React Native、weex、Flutter
- 操作dom获取datatable中的某一行的某一列的数据
- 从数据库取出两个同样的字符串用equals比较返回false
- re正则模块(二十五)
- (转)C# Textbox的ImeMode取值对中文输入法的影响
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
- vue-cli构建项目 npm run build后应该怎么运行在本地查看效果
- jQuery的安装
- BZOJ4813 CQOI2017小Q的棋盘(树形dp)
- 【Python学习笔记】异常处理try-except
- Java IO输入输出流 FileWriter 字符流
热门文章
- Android 控件布局常用的属性
- vue 组件用法
- 笔试算法题(03):最小第K个数 &; 判定BST后序序列
- MTK平台如何定位显示花屏和界面错乱等绘制异常的问题?
- CentOS 6.4 下用ntfs-3g挂载Windows NTFS分区
- 2018/3/4 Activiti教程之流程部署篇(与Springboot整合版)二
- 【NOIP2017】
- 安装adt-bundle-windows-x86-20130917时遇到的问题及解决方法
- spring-kafka
- jupyter-notebook添加python虚拟环境的kernel