严格按题解写,看能不能形成sum,只需要分割当前sum怎么由两边组成就好

#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2e4+;
int f[N][],g[N][];
int ret[N*],v[N],d[N],T,n,m;
struct Que
{
int l,r,c,sum,id;
} p[N*];
void cdq(int l,int r,int x,int y)
{
int mid=(l+r)>>;
vector<Que>lf,rt,cur;
lf.clear(),rt.clear(),cur.clear();
for(int i=x; i<=y; ++i)
{
if(p[i].l>mid)rt.push_back(p[i]);
else if(p[i].r<mid)lf.push_back(p[i]);
else cur.push_back(p[i]);
}
if(cur.size())
{
for(int i=; i<=; ++i)f[mid][i]=g[mid][i]=INF;
f[mid][v[mid]]=d[mid];
for(int i=mid-; i>=l; --i)
{
for(int j=; j<=; ++j)
{
if(j>=v[i])
{
if(j-v[i]==)f[i][j]=min(f[i+][j],d[i]);
else f[i][j]=min(f[i+][j],max(f[i+][j-v[i]],d[i]));
}
else f[i][j]=f[i+][j];
}
}
for(int i=mid+; i<=r; ++i)
{
for(int j=; j<=; ++j)
{
if(j>=v[i])
{
if(j-v[i]==)g[i][j]=min(g[i-][j],d[i]);
else g[i][j]=min(g[i-][j],max(g[i-][j-v[i]],d[i]));
}
else g[i][j]=g[i-][j];
}
}
for(int i=; i<cur.size(); ++i)
{
if(cur[i].r==mid)
{
if(f[cur[i].l][cur[i].sum]>cur[i].c)ret[cur[i].id]=;
continue;
}
bool flag=false;
for(int j=; j<=cur[i].sum; ++j)
{
int dis;
if(!j)dis=g[cur[i].r][cur[i].sum-j];
else if(j==cur[i].sum)dis=f[cur[i].l][j];
else dis=max(f[cur[i].l][j],g[cur[i].r][cur[i].sum-j]);
if(dis<=cur[i].c)
{
flag=true;
break;
}
}
if(!flag)ret[cur[i].id]=;
}
}
int cnt=x-;
if(lf.size())
{
for(int i=; i<lf.size(); ++i)
p[++cnt]=lf[i];
cdq(l,mid,x,cnt);
}
if(rt.size())
{
x=cnt+;
for(int i=; i<rt.size(); ++i)
p[++cnt]=rt[i];
cdq(mid+,r,x,cnt);
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; ++i)scanf("%d",&v[i]);
for(int i=; i<=n; ++i)scanf("%d",&d[i]);
for(int i=; i<=m; ++i)
{
scanf("%d%d%d%d",&p[i].l,&p[i].r,&p[i].c,&p[i].sum);
p[i].id=i;
ret[i]=;
}
cdq(,n,,m);
for(int i=; i<=m; ++i)printf("%d",ret[i]);
printf("\n");
}
return ;
}

HDU5808Price List Strike Back (BestCoder Round #86 E) cdq分治+背包的更多相关文章

  1. [HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP)

    [HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP) 题面 有三个人从一张N个点无重边的有向无环图上的三个点出发,每单位时间,他们分别选择当前 ...

  2. BestCoder Round #86 解题报告

    A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...

  3. BestCoder Round #86

    A题 Price List 巨水..........水的不敢相信. #include <cstdio> typedef long long LL; int main() { int T; ...

  4. HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002

    题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...

  5. BestCoder Round #86 部分题解

    Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/std ...

  6. HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp

    #include <cstdio> #include <cstring> #include <cmath> #include <vector> #inc ...

  7. HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分

    分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...

  8. HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理

    分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...

  9. HDU5804 Price List (BestCoder Round #86 A)水题

    分析:大于总和输出1 #include <cstdio> #include <cstring> #include <algorithm> using namespa ...

随机推荐

  1. 317. Shortest Distance from All Buildings

    题目: Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where th ...

  2. AdventureWorksDW2008R2 attach: Unable to open the physical file. Operating system error 5: "5(Access is denied.)

    http://stackoverflow.com/questions/26014133/adventureworksdw2008r2-attach-unable-to-open-the-physica ...

  3. .NET + OpenCV & Python + OpenCV 配置

    最近需要做一个图像识别的GUI应用,权衡了Opencv+ 1)QT,2)Python GUI,3).NET后选择了.NET... 本文给出C#+Opencv和Python+Opencv的相应参考,节省 ...

  4. 《Java编程那点事儿》读书笔记(四)——String和StringBuffer

    String 1.toString:显示对象内容时系统自动调用的方法. public class TOSTRING { public String toString(){ return "t ...

  5. R语言学习笔记——Base Graphics

    做exploratory data annalysis的作业,差点被虐死了,R从头开始,边做边学,最后搞到一点多才弄完,还有一个图怎么画都不对,最后发现是数据读取的时候有问题. 用来画图的数据来自:h ...

  6. spring mvc 国际化

    spring mvc 国际化 使用CookieLocaleResolver实现国际化的步骤:1.注册 messageSource,localeResolver 两个bean2.调用localeReso ...

  7. 自动化测试LoadRunner

    这个地址应该比较的好下载,以前找的地址都是需要输入一些相关的信息.这个只需要有一个HP的注册账号就可下载,记下来.以备后用: 下载地址: http://www8.hp.com/us/en/softwa ...

  8. hdu4430Yukari's Birthday(二分)

    4430 去年长春最简单一题 二分啊 错了好多遍  有个大坑 是个圆心处的1  可选可不选 #include <iostream> #include<cstdio> #incl ...

  9. Android开源库--SlidingMenu左右侧滑菜单

    如果说我比别人看得更远些,那是因为我站在了巨人的肩上.   github地址:https://github.com/jfeinstein10/SlidingMenu   设置: 1.下载之后以依赖项的 ...

  10. No resource found that matches the given name

    XML里面明显已经定义了ID,可是android:layout_toLeftOf="@id/text_seller"报错,说没有定义,原来这玩意要写在相对位置对象声明的下面,是有顺 ...