题意:

你现在有n个题目可以做,第i个题目需要的时间为t[i],你要选择其中的若干题目去做.
不妨令choose[i]表示第i个题目做不做.
定义cost=∑(i<=n)∑(i<=j<=n)(∏(i<=k<=j)choose[k])−∑(i<=n)choose[i]×t[i]
有q个询问,每个询问给出两个数p,x表示询问假设把t[p]修改成x,当你任意指定choose[]的值时,最大的cost是多少.

首先不考虑询问,dp一遍,f[i]表示前i个题目获得的最大收益,f[i]=max(f[i-1],max{f[j]+(i-j)*(i-j+1)-sum[i]+sum[j]}),斜率优化,正反各做一边

考虑询问,p要么选要么不选,不选的话很好说,选的话我们需要求出必选p整个序列的最大收益。

分治,每次处理必选x(mid<=x<=r),且x所在选择区间左端点在(l,mid),右端点在(mid,r)的答案,先求出以每个点为右端点的答案,再做一遍后缀最大值,就能求出每个x的答案。

第一次见分治还能这么用

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define N 300005
  4. #define rev reverse
  5. using namespace std;
  6. int n,t[N],st[N],top,m;
  7. int y[N],sum[N],f1[N],f2[N];
  8. void yu(int *f)
  9. {
  10. f[0]=0;top=0;st[++top]=0;
  11. for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
  12. for(int i=1;i<=n;i++)
  13. {
  14. f[i]=f[i-1];
  15. while(top>1&&y[st[top]]-y[st[top-1]]<=2*i*(st[top]-st[top-1]))top--;
  16. f[i]=max(f[i],f[st[top]]+(i-st[top])*(i-st[top]+1)/2-sum[i]+sum[st[top]]);
  17. y[i]=i*i-i+2*f[i]+2*sum[i];
  18. while(top>1&&(y[st[top]]-y[st[top-1]])*(i-st[top-1])<=(y[i]-y[st[top-1]])*(st[top]-st[top-1]))top--;
  19. st[++top]=i;
  20. }
  21. }
  22. int f[N],tmp[N];
  23. void solve(int *f1,int *f2,int l,int r)
  24. {
  25. if(l==r){f[l]=max(f[l],f1[l-1]+f2[l+1]-t[l]+1);return ;}
  26. int mid=(l+r)>>1;top=0;
  27. for(int i=l-1;i<mid;i++)
  28. {
  29. y[i]=i*i-i+2*f1[i]+2*sum[i];
  30. while(top>1&&(y[st[top]]-y[st[top-1]])*(i-st[top-1])<=(y[i]-y[st[top-1]])*(st[top]-st[top-1]))top--;
  31. st[++top]=i;
  32. }
  33. for(int i=mid;i<=r;i++)
  34. {
  35. while(top>1&&y[st[top]]-y[st[top-1]]<=2*i*(st[top]-st[top-1]))top--;
  36. tmp[i]=f2[i+1]+f1[st[top]]-sum[i]+sum[st[top]]+(i-st[top])*(i-st[top]+1)/2;
  37. }
  38. for(int i=r-1;i>=mid;i--)tmp[i]=max(tmp[i],tmp[i+1]);
  39. for(int i=mid;i<=r;i++)f[i]=max(f[i],tmp[i]);
  40. solve(f1,f2,l,mid);solve(f1,f2,mid+1,r);
  41. }
  42. signed main()
  43. {
  44. scanf("%lld",&n);
  45. for(int i=1;i<=n;i++)scanf("%lld",&t[i]);
  46.  
  47. yu(f1);rev(t+1,t+n+1);
  48. yu(f2);
  49. rev(t+1,t+n+1);rev(f2+1,f2+n+1);
  50. for(int i=1;i<=n;i++)f[i]=-t[i];
  51. for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
  52. solve(f1,f2,1,n);
  53.  
  54. rev(t+1,t+n+1);rev(f+1,f+n+1);rev(f1+1,f1+n+1);rev(f2+1,f2+n+1);
  55. for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
  56. solve(f2,f1,1,n);
  57. rev(t+1,t+n+1);rev(f+1,f+n+1);rev(f2+1,f2+n+1);rev(f1+1,f1+n+1);
  58.  
  59. scanf("%lld",&m);
  60. for(int i=1;i<=m;i++)
  61. {
  62. int t1,t2;scanf("%lld%lld",&t1,&t2);
  63. printf("%lld\n",max(f1[t1-1]+f2[t1+1],f[t1]-t2+t[t1]));
  64. }
  65. return 0;
  66. }

  

AtCoder Regular Contest 066 F Contest with Drinks Hard的更多相关文章

  1. Atcoder Regular Contest 066 F genocide【JZOJ5451】

    题目 分析 \(s[i]\)表示a前缀和. 设\(f[i]\)表示做完了1~i的友谊颗粒的最优值(不一定选i),那么转移方程为 \[f[i]=max\{f[i-1],max\{f[j]-s[i]+s[ ...

  2. AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图

    AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图 链接 AtCoder 大意 在数轴上放上n个点,点i可能的位置有\(x_i\)或者\(y_i\ ...

  3. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  4. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  5. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  6. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  7. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  8. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  9. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

随机推荐

  1. 基于Ping和Telnet/NC的监控脚本案例分析

    案例一:单纯地对某些ip进行ping监控 [root@test opt]# cat /opt/hosts_ip_list 192.168.10.10 192.168.10.11 192.168.10. ...

  2. Netdata---Linux系统性能实时监控平台部署记录

    通常来说,作为一个Linux的SA,很有必要掌握一个专门的系统监控工具,以便能随时了解系统资源的占用情况.下面就介绍下一款Linux性能实时监测工具-Netdata,它是Linux系统实时性能监测工具 ...

  3. required: true,el-upload :action="UploadUrl()"

    <el-form-item label="所属班级:" prop="Name" :rules="[{ required: true, messa ...

  4. 个人阅读作业 final

    前两次阅读作业链接: http://www.cnblogs.com/SteelPillar/p/4027877.html http://www.cnblogs.com/SteelPillar/p/40 ...

  5. rabbitMq实现与zookeeper类似的watcher功能

    场景:A.B.C.D(可以是一个机器的不同进程,也可以是不同机器的进程)启动了相同的项目,使用同一个数据库.但是,如果A修改了数据库的数据,需要B.C.D在很短的时间能够知道数据库发生了修改.当然可以 ...

  6. Scrum Meeting 9

                第九次会议 No_00:工作情况 No_01:任务说明 待完成 已完成 No_10:燃尽图 No_11:照片记录 待更新 No_100:代码/文档签入记录 No_101:出席表 ...

  7. 《Linux内核分析》第13章

    <Linux内核设计与实现>第十三章--虚拟文件系统概述 20135211 一.通用文件系统接口 之所以可以使用这种通用接口(VF)对所有类型的文件系统进行操作,是因为内核在它的底层文件系 ...

  8. Linux内核设计期中总结

    Linux内核设计期中总结 ● 知识点 一.计算机是如何工作的 计算机是按照冯·诺依曼存储程序的原理. 在执行程序时须先将要执行的相关程序和数据放入内存储器中,在执行程序时CPU根据当前程序指针寄存器 ...

  9. Sprint 冲刺第三阶段第二天

    陈汝婷:播放音乐 1:做播放音乐这个功能时开始没有考虑周全,使用 PS P出来的图竟然没有用上,耗时耗人工.吃一见长一智,以后要考虑周全.还要耗了那么久,音乐的初效果终于出来了. 2:昨天出现的问题, ...

  10. There are no enabled repos.

    今天要记录一下自己懵逼的一天,原来自己是Ubuntu系统,还以为是centos,导致命令错了 There are no enabled repos. Run "yum repolist al ...