布谷。

欢迎大家来不耻下问。

这里是正解不会,暴力写跪,乱搞鸡肋的某虻 。


好想放假啊!!!!

话说猫厂现在产量低迷……

ZJ一下:

T1,三维偏序,只码了$\Theta(N^2)$暴力

T2,暴力愉快。

T3,输〇片分。

简单TJ:

T1

因为这个题的要求比较特殊,求解的答案可以和一个输入的顺序一起维护。

首先通过排序将$A$数组的偏序限制解决

然后用树状数组暴干$B$数组的大小,将位置插入树状数组比较维护。

最后的答案直接查即可。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <vector>
#include <cstdio>
#define N 555555
#define LL long long using namespace std; const int lim=500000;
LL pn;
struct PRE{
LL id,pa,pb;
}ps[N];
vector<LL>vls;
LL pre[N];
LL ans=0; inline LL fvind(LL a){
return lower_bound(vls.begin(),vls.end(),a)-vls.begin()+1;
}
inline LL lowbit(int x){
return x&(-x);
}
void add(LL pos,LL val){
while(pos<=lim){
pre[pos]=min(pre[pos],val);
pos+=lowbit(pos);
}
}
LL query(LL pos){
LL res=LLONG_MAX;
while(pos){
res=min(res,pre[pos]);
pos-=lowbit(pos);
}
return res;
}
int main(){
LL a;
ios_base::sync_with_stdio(false);
cin>>pn;
for(int i=1;i<=pn;i++)ps[i].id=i;
for(int i=1;i<=pn;i++){
cin>>a;
ps[i].pa=ps[i-1].pa+a;
}
vls.push_back(0);
for(int i=1;i<=pn;i++){
cin>>a;
ps[i].pb=ps[i-1].pb+a;
vls.push_back(ps[i].pb);
}
// for(auto i:vls){\
cout<<i<<" ";\
}cout<<endl;
sort(vls.begin(),vls.end());
vls.erase(unique(vls.begin(),vls.end()),vls.end());
// for(auto i:vls){\
cout<<i<<" ";\
}cout<<endl;
for(int i=0;i<=pn;i++){
ps[i].pb=fvind(ps[i].pb);
}
sort(ps,ps+pn+1,[](const PRE &a,const PRE &b)
{return a.pa==b.pa?a.id<b.id:a.pa<b.pa;});
// for(int i=1;i<=pn;i++){\
cout<<ps[i].pa<<" "<<ps[i].pb<<" "<<ps[i].id<<endl;\
}
memset(pre,0x7f,sizeof pre);
// add(ps[0].pb,0);
for(int i=0;i<=pn;i++){
LL vl=query(ps[i].pb);//cout<<ps[i].id<<"val:"<<vl<<endl;
add(ps[i].pb,ps[i].id);
ans=max(ans,ps[i].id-vl);
}
cout<<ans<<endl;
}

T2

证明先咕下。

利用决策单调性,将$\Theta(N^3)$优化成$\Theta(N^2)$

#include <iostream>
#include <climits>
#include <cstring>
#include <cstdio>
#define N 5555
#define LL long long using namespace std; int pn;
LL arr[N],pre[N],
dp[N][N],
ap[N][N]; int main(){
cin.sync_with_stdio(false);
cin>>pn;
for(int i=1;i<=pn;i++){
cin>>arr[i];
pre[i]=pre[i-1]+arr[i];
}
for(int i=1;i<=pn;i++){
for(int j=1;j<=pn;j++){
if(i<=j)dp[i][j]=LLONG_MAX/3;
else dp[i][j]=0;
}
}
for(int i=1;i<=pn;i++){
dp[i][i]=arr[i];
ap[i][i]=i;
}
for(int i=1;i<pn;i++){
for(int j=1;j+i<=pn;j++){
int l=j,r=j+i;
// cout<<l<<" "<<r<<endl;
// cout<<ap[l][r-1]<<"~"<<ap[l+1][r]<<endl;
for(int k=ap[l][r-1];k<=ap[l+1][r];k++){
// cout<<dp[l][r]<<" <<<< "<<dp[l][k-1]<<"+"<<dp[k+1][r]<<endl;
if(dp[l][r]>dp[l][k-1]+dp[k+1][r]){
dp[l][r]=dp[l][k-1]+dp[k+1][r];
ap[l][r]=k;
}
}
dp[l][r]+=pre[r]-pre[l-1];
}
}
cout<<dp[1][pn]<<endl;
}

T3

大神题,好像和一些神奇的高斯消元有关。

19-10-29-Night-X的更多相关文章

  1. 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox

    [源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...

  2. SpringBoot+mybatis:报错Fri Oct 19 14:29:24 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requiremen

    报错:Fri Oct 19 14:29:24 CST 2018 WARN: Establishing SSL connection without server's identity verifica ...

  3. 【Selenium】【BugList9】windows环境,fp = open("./"+ time.strftime("%Y-%m-%d %H:%M:%S") + " result.html",'wb'),报错:OSError: [Errno 22] Invalid argument: './2018-09-05 10:29:32 result.html'

    [代码] if __name__=="__main__": suite = unittest.TestSuite() suite.addTest(Baidu("test_ ...

  4. 10.29 正睿停课训练 Day11

    目录 2018.10.29 正睿停课训练 Day11 A 线段树什么的最讨厌了(思路 DFS) B 已经没有什么好害怕的了(差分 前缀和) C 我才不是萝莉控呢(DP 贪心 哈夫曼树) 考试代码 A ...

  5. 第17次Scrum会议(10/29)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/29 17:20~17:42,总计22min.地点:东北师 ...

  6. Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24

    作者 | 木苏.进超.冬岛.元毅.心水.衷源 业界要闻 1.云原生编程语言 Pulumi 1.0 pulumi ,一款中立的开源云开发平台,Pulumi 支持多语言.混合云环境.完全可扩展.初期支持 ...

  7. [Linux] 在 Ubuntu 19.10 上开启 SSH 服务并允许远程登录

    在 Ubuntu 19.10 上安装 SSH,并开启服务 0.检查并确认系统当前是否已安装SSH: sudo ps -e | grep ssh 如果只有 ssh-agent 说明 ssh-server ...

  8. [Linux] 树莓派 4B 安装 Ubuntu 19.10 (Eoan Ermine) IOT 版

    硬件:Raspberry Pi 4B系统:Ubuntu 19.10 (Eoan Ermine) for IOT官网:https://ubuntu.com/download/iot/raspberry- ...

  9. 2016.10.29初中部上午NOIP普及组比赛总结

    2016.10.29[初中部 NOIP普及组 ]模拟赛 做得好爽! 进度: 比赛:35+45+AC+0=180 改题:AC+AC+AC+0=300 幸运的数 有点无语--之前怕超限,还特意利用程序打了 ...

  10. Ubuntu 19.10 安装 jupyter

    安装pip3 ubuntu 19.10 已经没有python了,取代的是python3. 执行sudo apt install python3-pip安装pip3 安装jupyter 执行sudo p ...

随机推荐

  1. enumrate用法

    转自*https://www.runoob.com/python/python-func-enumerate.html*侵删 描述 enumerate() 函数用于将一个可遍历的数据对象(如列表.元组 ...

  2. dl,dt,dd标签 VS 传统table实现数据列表

    过去有很多网页设计师喜欢将他们的网页效果图用table布局实现成网页,但是这样做会遇到一个比较麻烦的问题就是,后期调试和维护会相当的困难.现在,越来越多的前端开发er们开始使用xHTML+CSS替代最 ...

  3. 【笔记篇】斜率优化dp(五) USACO08MAR土地购(征)买(用)Land Acquisition

    好好的题目连个名字都不统一.. 看到这种最大最小的就先排个序嘛= =以x为第一关键字, y为第二关键字排序. 然后有一些\(x_i<=x_{i+1},且y_i<=y_{i+1}\)的土地就 ...

  4. 【学术篇】SDOI2009 学校食堂

    传送门~ 题目大意 先分析\((x\ or\ y)-(x\ and\ y)\), 就是\(x\)和\(y\)中存在的1减去\(x\)和\(y\)中相同的1 *那不就是\(x\ xor\ y\)么←_← ...

  5. python库之sklearn

     一.安装sklearn conda install scikit-learn 参考文献 [1]整体介绍sklearn https://blog.csdn.net/u014248127/article ...

  6. css---文本新增样式

    opacity属性指定了一个元素的透明度 默认值:1.0 不可继承    兼容性不是太好 兼容性写法 opacity{ opacity:0.5; filter:alpha(opacity=); //f ...

  7. CSS——背景渐变

    在线性渐变过程中,颜色沿着一条直线过渡:从左侧到右侧.从右侧到左侧.从顶部到底部.从底部到顶部或着沿任何任意轴.如果你曾使用过制作图件,比如说Photoshop,你对线性渐变并不会陌生. 兼容性问题很 ...

  8. (转)JNI入门教程之HelloWorld篇 .

    转: http://blog.csdn.net/mingjava/article/details/180946 本文讲述如何使用JNI技术实现HelloWorld,目的是让读者熟悉JNI的机制并编写第 ...

  9. class.forname & classloader

    From https://www.cnblogs.com/gaojing/archive/2012/03/15/2413638.html 传统的使用jdbc来访问数据库的流程为: Class.forN ...

  10. django中写form表单时csrf_token的作用

    之前在学习django的时候,在template中写form时,出现错误.百度,google后要加{% csrf_token %}才可以,之前一直也没研究,只是知道要加个这个东西,具体是什么也不明白. ...