首页 技术 正文
技术 2022年11月23日
0 收藏 633 点赞 4,693 浏览 1240 个字

CTSC2018 Day2T1 Juice混合果汁

【题解】

  在考场上A掉的题。

  把美味度排个序,然后按照价格p为权值建立主席树,把每个果汁按照拍好的顺序添加进去。主席树上维护总升数cnt以及总价格sum。对于每个询问,我们二分一个美味值,check的时候去主席树上查找大于等于这个美味值的果汁中购买L升的价格即可。

  

 #include<cstdio>
#include<algorithm>
#define LL long long
#define rg register
#define N 100010
#define ls (a[u].l)
#define rs (a[u].r)
using namespace std;
int n,m,n2,tot,rt[N];
LL cnt,sum,G,L;
struct rec{
int d,p,l;
}jui[N];
struct tree{
LL cnt,sum; int l,r;
}a[];
inline LL read(){
LL k=; int f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline bool cmp(rec a,rec b){return a.d>b.d;}
void add(int &u,int l,int r,int pos){
a[++tot]=a[u]; a[u=tot].cnt+=cnt; a[u].sum+=sum;
int mid=(l+r)>>;
if(l<r)
if(pos<=mid) add(ls,l,mid,pos);
else add(rs,mid+,r,pos);
}
LL query(int u,int l,int r,LL k){
if(l==r) return a[u].cnt<k?G+:k*l;
int mid=(l+r)>>;
if(a[ls].cnt>=k) return query(ls,l,mid,k);
else return query(rs,mid+,r,k-a[ls].cnt)+a[ls].sum;
}
int main(){
n=read(); m=read();
for(rg int i=;i<=n;i++){
jui[i].d=read(); jui[i].p=read(); jui[i].l=read();
n2=max(n2,jui[i].p);
}
sort(jui+,jui++n,cmp);
for(rg int i=;i<=n;i++){
cnt=jui[i].l; sum=1ll*cnt*jui[i].p;
add(rt[i]=rt[i-],,n2,jui[i].p);
}
while(m--){
G=read(); L=read();
int l=,r=n+;
while(l+<r){
int mid=(l+r)>>;
if(query(rt[mid],,n2,L)>G) l=mid;
else r=mid;
}
printf("%d\n",r<=n?jui[r].d:-);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,762
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838