先看成一条链

for一遍找位置

在for一遍算答案

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<string>
  5. #include<cstdio>
  6. #include<cmath>
  7. using namespace std;
  8.  
  9. typedef long long LL;
  10.  
  11. #define N 100010
  12.  
  13. int n;
  14. int cnt=;
  15.  
  16. int a[N<<],s[N<<];
  17.  
  18. int main()
  19. {
  20. freopen("a.in","r",stdin);freopen("a.out","w",stdout);
  21. scanf("%d",&n);
  22. for (int i=;i<=n;i++)
  23. scanf("%d",&a[i]),a[n+i]=a[i];
  24. for (int i=;i<=n*;i++)
  25. {
  26. if (i==cnt+n)
  27. break;
  28. s[i]=s[i-]+a[i]-;
  29. while (s[i]<s[cnt-])
  30. cnt++;
  31. }
  32. LL ans=;
  33. int l=cnt+n-,r=cnt+n-;
  34. while (r>=cnt)
  35. {
  36. while (!a[l])
  37. l--;
  38. ans+=(LL)(r-l)*(r-l);
  39. a[l]--;
  40. r--;
  41. }
  42. printf("%lld\n",ans);
  43. return ;
  44. }

【bzoj4412】[Usaco2016 Feb]Circular Barn的更多相关文章

  1. bzoj 4412: [Usaco2016 Feb]Circular Barn

    4412: [Usaco2016 Feb]Circular Barn Description 有一个N个点的环,相邻两个点距离是1.点顺时针标号为1..N.每一个点有ci头牛,保证∑ci=N.每头牛都 ...

  2. BZOJ4409 [Usaco2016 Feb]Circular barn 动态规划 斜率优化

    原文链接http://www.cnblogs.com/zhouzhendong/p/8724739.html 题目传送门 - BZOJ4409 题意 有一个N个点的环,相邻两个点距离是1.点顺时针标号 ...

  3. 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈

    [BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...

  4. 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树

    [BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...

  5. 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树

    [BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...

  6. 【BZOJ3943】[Usaco2015 Feb]SuperBull 最大生成树

    [BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...

  7. 树状数组【bzoj1782】: [Usaco2010 Feb]slowdown 慢慢游

    [bzoj1782]: [Usaco2010 Feb]slowdown 慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N) ...

  8. 【BZOJ3940】[USACO2015 Feb] Censoring (AC自动机的小应用)

    点此看题面 大致题意: 给你一个文本串和\(N\)个模式串,要你将每一个模式串从文本串中删去.(此题是[BZOJ3942][Usaco2015 Feb]Censoring的升级版) \(AC\)自动机 ...

  9. 带权并查集【bzoj3362】: [Usaco2004 Feb]Navigation Nightmare 导航噩梦

    [bzoj]3362: [Usaco2004 Feb]Navigation Nightmare 导航噩梦 ​ 农夫约翰有N(2≤N≤40000)个农场,标号1到N,M(2≤M≤40000)条的不同的垂 ...

随机推荐

  1. CSS Paint API绘制透明格子背景实例页面

    CSS代码: .box { width: 180px; height: 180px; background: paint(transparent-grid); } HTML代码: <div cl ...

  2. Python 文件修改-函数介绍

    上节课复习:1.字符编码 1.1 如何解决乱码问题: 字符存取使用的编码标准不一致 1.2 文件头 在文件的首行写入文件头,用于控制Python解释器读取py文件内容时使用的编码 #coding:文件 ...

  3. Python之面向对象函数式编程

    Python之面向对象函数式编程 函数式编程的根本就是用 def 去模拟数学式的编程逻辑. 类似与 y = 2*x + 1 ,当x = 3 时,函数的结果y就得7. def test(x): retu ...

  4. python 库文件版本收集及安装

    版本收集:pip freeze > require.txt版本安装:pip install -r require.txt

  5. LeetCode(56)Merge Intervals

    题目 Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6], ...

  6. 绑定IP 绑定设备

    首先引别人的组播测试如下 1. 一个udp client可以同时往多个组播地址发送数据,多个udpclient可以同时往一个组播发数据. 2. 本地udp必须监听组播端口,否则收不到数据.3. 一个u ...

  7. angular2集成highchart

    集成highchart的配置困扰了我很久,今天终于解决了: 1.修改tsconfig.app.json: "compilerOptions": { //... "type ...

  8. LaTex/Overleaf使用笔记

    1. 添加网页引用 @misc{ r1,   author = "Wikipedia",   title = "Binary decision diagram --- { ...

  9. Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~

    B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...

  10. bzoj——3555: [Ctsc2014]企鹅QQ

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 2617  Solved: 921[Submit][Statu ...