codeforces 436F Banners

本文探讨了一种算法,用于帮助开发者确定应用程序的最佳定价策略和广告容忍度,以最大化收益。通过将用户按其对广告的容忍度排序,并采用分块和凸包技巧来高效计算不同广告数量下的最佳付费版本价格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.elijahqi.win/2018/03/07/codeforces-436f-banners/
All modern mobile applications are divided into free and paid. Even a single application developers often release two versions: a paid version without ads and a free version with ads. Suppose that a paid version of the app costs p p ( p p is an integer) rubles, and the free version of the application contains c c ad banners. Each user can be described by two integers: a_{i} a i ​ — the number of rubles this user is willing to pay for the paid version of the application, and b_{i} b i ​ — the number of banners he is willing to tolerate in the free version. The behavior of each member shall be considered strictly deterministic: if for user i i , value b_{i} b i ​ is at least c c , then he uses the free version, otherwise, if value a_{i} a i ​ is at least p p , then he buys the paid version without advertising, otherwise the user simply does not use the application. Each user of the free version brings the profit of c×w c×w rubles. Each user of the paid version brings the profit of p p rubles. Your task is to help the application developers to select the optimal parameters p p and c c . Namely, knowing all the characteristics of users, for each value of c c from 0 0 to (maxbi)+1 ( m a x b i ) + 1 you need to determine the maximum profit from the application and the corresponding parameter p p . 输入输出格式 输入格式: The first line contains two integers n n and w w (1<=n<=105;1<=w<=105) ( 1 <= n <= 10 5 ; 1 <= w <= 10 5 ) — the number of users and the profit from a single banner. Each of the next n n lines contains two integers a_{i} a i ​ and b_{i} b i ​ (0<=a_{i},b_{i}<=10^{5}) (0<=a i ​ ,b i ​ <=10 5 ) — the characteristics of the i i -th user. 输出格式: Print (maxbi)+2 ( m a x b i ) + 2 lines, in the i i -th line print two integers: pay pay — the maximum gained profit at c=i-1 c=i−1 , p p (0<=p<=10^{9}) (0<=p<=10 9 ) — the corresponding optimal app cost. If there are multiple optimal solutions, print any of them. 输入输出样例 输入样例#1: 复制 2 1 2 0 0 2 输出样例#1: 复制 0 3 3 2 4 2 2 2 输入样例#2: 复制 3 1 3 1 2 2 1 3 输出样例#2: 复制 0 4 3 4 7 3 7 2 4 2
给定每个客人忍受广告的篇幅数 如果没超过了这个值 他会使用免费版本 再给定一个
付费值 如果不到他这个承受能力则他会使用付费版 那么首先针对这个b对所有的客人排序 这样的话每次询问c的时候广告的收益可以o(1)算 但是这个付费的价值我们就不能确定了,因为随着广告的递增我会有人去用付费版本那么我们针对付费分块 每个块里维护一个凸包 维护付费价格在这个区间的最优答案的下凸曲线 设i<j d(i)>d(j) 那么当我们增加这个付费的人数为x的时候如果出现d(i)+x*i≤d(j)+x*j那么显然我i再也不可能是答案了,所以用d(i)-d(j)/(j-i)维护这个斜率单增的下凸曲线即可 复杂度为什么对得,因为整块的直接打标记即可 如果不是整块也只需要暴力重构sqrt(n)大小的块即可

#include<cmath>
#include<cstdio>
#include<algorithm>
#define N 110000
#define N1 350
#define ll long long
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=gc();
    return x*f;
}
struct node{
    int a,b;
    inline friend bool operator <(const node &a,const node &b){
        return a.b<b.b;
    }
}data[N];
int q[N1][N1],ql[N1],qr[N1],left[N1],right[N1],cnt[N1],b[N],n,w,nn;
ll d[N];
inline double slope(int i,int j){return (double)(d[i]-d[j])/(j-i);}
inline void solve(int id,int x){
    while(ql[id]<qr[id]&&slope(q[id][ql[id]],q[id][ql[id]+1])<=x) ++ql[id];
}
inline void rebuild(int x,int l,int r){
    ql[x]=1,qr[x]=0;
    for (int i=l;i<=r;++i){
        while(ql[x]<qr[x]&&slope(q[x][qr[x]],i)<slope(q[x][qr[x]-1],q[x][qr[x]])) --qr[x];
        q[x][++qr[x]]=i;
    }solve(x,0);
}
inline void add(int x){
    if (!x) return;int id=b[x];
    for (int i=1;i<id;++i) solve(i,++cnt[i]);
    for (int i=left[id];i<=right[id];++i) d[i]+=(ll)cnt[id]*i;
    for (int i=left[id];i<=x;++i) d[i]+=i;cnt[id]=0;rebuild(id,left[id],right[id]);
}
int main(){
//  freopen("cf436f.in","r",stdin);
    n=read();w=read();int mx1=0,mx2=0,x1,x2;
    for (int i=1;i<=n;++i) data[i].a=x1=read(),data[i].b=x2=read(),mx1=max(mx1,x1),mx2=max(mx2,x2);
    nn=sqrt(mx1);sort(data+1,data+n+1);for (int i=1;i<=mx1;++i) b[i]=(i-1)/nn+1;int now=1;
    for (int i=1;i<=b[mx1];++i) left[i]=(i-1)*nn+1,right[i]=min(mx1,i*nn),ql[i]=1;
    for (int i=0;i<=mx2+1;++i){
        while(now<=n&&data[now].b<i) add(data[now++].a);ll ans=0;int ans1=0;
        for (int j=1;j<=b[mx1];++j){int l=q[j][ql[j]];if (d[l]+(ll)cnt[j]*l>ans) ans=d[l]+(ll)cnt[j]*l,ans1=l;}
        printf("%lld %d\n",ans+(ll)w*i*(n-now+1),ans1);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值