传送门

我们先把果汁按照美味度排序,枚举\(d\),那么肯定是贪心的选择美味程度不小于\(d\)的且最便宜的果汁

发现\(d\)可以二分,那么在主席树上二分就可以了

据说还有整体二分的大佬然而我并不会

//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
ll read(){
R ll res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+5;
struct qwq{
int d,p,l;
inline bool operator <(const qwq &b)const{return d<b.d;}
}a[N];
struct node{int ls,rs;ll s,w;}tr[N*20];
int rt[N],n,m,lim,cnt,las;ll res;
void update(int &p,int l,int r,int x,int s,ll w){
tr[++cnt]=tr[p],p=cnt,tr[p].s+=s,tr[p].w+=w;
if(l==r)return;int mid=(l+r)>>1;
x<=mid?update(tr[p].ls,l,mid,x,s,w):update(tr[p].rs,mid+1,r,x,s,w);
}
ll query(int p,int l,int r,ll s){
if(l==r)return l*s;
int mid=(l+r)>>1;
if(tr[tr[p].ls].s>=s)return query(tr[p].ls,l,mid,s);
return tr[tr[p].ls].w+query(tr[p].rs,mid+1,r,s-tr[tr[p].ls].s);
}
void solve(){
ll G=read(),L=read();
int l=0,r=n,ans=0,mid;
while(l<=r){
mid=(l+r)>>1;
if(tr[rt[mid]].s>=L&&query(rt[mid],1,lim,L)<=G)l=mid+1,ans=mid;
else r=mid-1;
}print(a[ans].d);
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),m=read(),a[0].d=-1;
fp(i,1,n)a[i].d=read(),a[i].p=read(),a[i].l=read(),cmax(lim,a[i].p);
sort(a+1,a+1+n);
fd(i,n,1)update(rt[i]=rt[i+1],1,lim,a[i].p,a[i].l,1ll*a[i].p*a[i].l);
rt[0]=rt[1];while(m--)solve();
return Ot(),0;
}

uoj#402. 【CTSC2018】混合果汁(主席树+二分)的更多相关文章

  1. BZOJ5343[Ctsc2018]混合果汁——主席树+二分答案

    题目链接: CTSC2018混合果汁 显然如果美味度高的合法那么美味度低的一定合法,因为美味度低的可选方案包含美味度高的可选方案. 那么我们二分一个美味度作为答案然后考虑如何验证? 选择时显然要贪心的 ...

  2. 洛谷P4602 [CTSC2018]混合果汁(主席树)

    题目描述 小 R 热衷于做黑暗料理,尤其是混合果汁. 商店里有 nn 种果汁,编号为 0,1,\cdots,n-10,1,⋯,n−1 . ii 号果汁的美味度是 d_idi​ ,每升价格为 p_ipi ...

  3. Luogu P4062 [CTSC2018]混合果汁 (主席树)

    二分$d$, 转为判断判断是否能取到$Lj$升, 再可持久化一下就好了 #include <iostream> #include <algorithm> #include &l ...

  4. 2018湘潭邀请赛C题(主席树+二分)

    题目地址:https://www.icpc.camp/contests/6CP5W4knRaIRgU 比赛的时候知道这题是用主席树+二分,可是当时没有学主席树,就连有模板都不敢套,因为代码实在是太长了 ...

  5. BZOJ.1926.[SDOI2010]粟粟的书架(前缀和 主席树 二分)

    题目链接 题意: 在给定矩形区域内找出最少的数,满足和>=k.输出数的个数.两种数据范围. 0~50 注意到(真没注意到...)P[i,j]<=1000,我们可以利用前缀和预处理. num ...

  6. 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)

    Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...

  7. HDU - 4866 主席树 二分

    题意:在x轴\([1,X]\)内的上空分布有n个占据空间\([L_i,R_i]\),高度\(D_i\)的线段,射中线段的得分为其高度,每次询问从x轴的\(x\)往上空射的最近k个线段的总得分,具体得分 ...

  8. POJ 6621: K-th Closest Distance(主席树 + 二分)

    K-th Closest Distance Time Limit: 20000/15000 MS (Java/Others)    Memory Limit: 524288/524288 K (Jav ...

  9. HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分)

    HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分) 传送门:http://acm.hdu.edu.cn/showproblem.php? ...

随机推荐

  1. redis的安装与类型

    redis Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件 源码安装 redis , 编译安装 为何用源码安装,不用yum安装, 编译安装的优势 ...

  2. 电话聊天狂人 【STL】

    7-2 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤10​5​​),为通话记录条数.随后N行,每行给出一条通话记录.简单起 ...

  3. EntityFramework codefirst

    一.Entity Framework 迁移命令(get-help EntityFramework) Enable-Migrations 启用迁移 Add-Migration 为挂起的Model变化添加 ...

  4. process调用protothread机制的相关宏定义——用HelloWorld进程诠释

    一.HelloWorld例子 #include "contiki.h" #include <stdio.h> /* For printf() */ /*-------- ...

  5. nginx 部署thinkphp 做的东西, 配置 Pathinfo 模式,终于配好了

    用thinkphp做了一个网站,部署到ubuntu上的时候需要,服务器用的是nginx,本身不支持pathinfo模式,需要修改配置文件,使其能够用pathinfo. 我用的是虚拟主机的方式.之前配置 ...

  6. Could not find JSON in http://updates.jenkins-ci.org/update-center.json?id=default&version=2.7.4

    14-Sep-2016 21:43:58.241 INFO [Download metadata thread] hudson.model.AsyncPeriodicWork$1.run Finish ...

  7. ffmpeg去水印

    1.用potplayer打开有水印的视频文件,截图一张待用.2.用IrfanView打开保存的图片,调整到100%大小,按住鼠标左键框选水印位置,记下标题“Selection:”右边的4组数字.3.f ...

  8. L95

    The children squealed with delight when they saw the puppy.The signal will be converted into digital ...

  9. python 生成特定间隔数列的方法

    (1)range() 和 xrange( )[python内置函数] range(开始,结束,间隔). 值得注意的是:生成数列最后一个数< 结束值. 返回结果类型:list,其中元素是integ ...

  10. 华为USG6500系列

    华为USG6500: ssh 登录配置 time-range 相关配置:<USG6000V1>system-view Enter system view, return user view ...