布谷。

欢迎大家来不耻下问。

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


好想放假啊!!!!

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

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. POJ 1946 Cow Cycling

    Cow Cycling Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2516   Accepted: 1396 Descr ...

  2. BeanShell Sampler生成uuid

  3. Windows XP浏览器支持度

    XP最多支持到IE8 谷歌已经结束对Windows XP版Chrome浏览器的支持. 2015年11月,谷歌表示会在2015年结束后,结束对Windows XP版Chrome浏览器的支持.而今,随着2 ...

  4. 【JZOJ4905】【BZOJ4720】【luoguP1850】换教室

    description 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程.在可以选择的课程中,有2n节课程安排在n个时间段上.在第i(1≤i≤n)个时间段上,两节内容相同的课 ...

  5. Remember, every day is a miracle.

    Remember, every day is a miracle.请记住,每一天都是一个奇迹.

  6. NOI2001 炮兵阵地 洛谷2704

    题目描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P&quo ...

  7. (转)详解HttpURLConnection

    请求响应流程 设置连接参数的方法 setAllowUserInteraction setDoInput setDoOutput setIfModifiedSince setUseCaches setD ...

  8. clover无缘无故隐藏书签栏原因

    可能是不小心按住了Ctrl+shift+B

  9. MongoDB后台运行

    文章目录 命令方式(推荐) 命令行和配置文件方式 命令行: 配置文件: 命令方式(推荐) 如果想在后台运行,启动时只需添加 --fork函数即可. fork: 以守护进程的方式运行MongoDB. 指 ...

  10. JS if 判断

    if条件判断 1.语法结构——只判断true,不判断false if(条件判断:结果只有两个true或false) { 条件为true,将执行该代码: } 说明:   if是系统关键字,必须全小写. ...