codeforces Cloud Computing

本文探讨了Buber公司从传统基础设施向云平台迁移的过程,特别是在连续租用CPU核心以优化成本方面的策略。通过分析不同计费计划,利用数据结构进行高效计算,以确保在满足业务需求的同时,实现最小化的财务支出。

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

Buber is a Berland technology company that specializes in waste of investor’s money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for nnn consecutive days, which are numbered from 111 to nnn. Buber requires kkk CPU cores each day.

The cloud provider offers mmm tariff plans, the iii-th tariff plan is characterized by the following parameters:

  • lil_ili and rir_iri — the iii-th tariff plan is available only on days from lil_ili to rir_iri, inclusive,
  • cic_ici — the number of cores per day available for rent on the iii-th tariff plan,
  • pip_ipi — the price of renting one core per day on the iii-th tariff plan.

Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to cic_ici) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.

Find the minimum amount of money that Buber will pay for its work for nnn days from 111 to nnn. If on a day the total number of cores for all available tariff plans is strictly less than kkk, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly kkk cores this day.

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000006;
const int N = 1000000;

struct Seg{
    long long cnt, sum;
} seg[MAXN*4];

void update(int o, int l, int r, int P, int C){
    if (r<P || P<l) return;
    if (l==r){
        seg[o].cnt += C;
        seg[o].sum += (long long)r*C;
        cout << o << " " << l << " " << r << " " << P << " " << C << endl;
        cout << seg[o].cnt << " " << seg[o].sum << endl;
        return;
    }
    int mid = (l+r)>>1;
    update(o<<1,l,mid,P,C);
    update(o<<1|1,mid+1,r,P,C);
    seg[o].cnt = seg[o<<1].cnt + seg[o<<1|1].cnt;
    seg[o].sum = seg[o<<1].sum + seg[o<<1|1].sum;
}

long long query(int o, int l, int r, int K){
    if ( seg[o].cnt <= K ) return seg[o].sum;
    if ( l==r ) return seg[o].sum / seg[o].cnt * K;
    int mid = (l+r)>>1;
    long long ret = query(o<<1,l,mid,K);
    if ( seg[o<<1].cnt < K ) ret += query(o<<1|1,mid+1,r,K-seg[o<<1].cnt);
    return ret;
}

int n, k, m;
vector< pair<int,int> > Events[MAXN];

void init(){
    cin >> n >> k >> m;
    for (int i=0; i<m; i++){
        int l, r, c, p;
        cin >> l >> r >> c >> p;
        Events[l].push_back( {p,c} );
        Events[r+1].push_back( {p,-c} );
    }
}

void solve(){
    long long ans = 0;
    for (int i=0; i<=n; i++){
        for (auto &e:Events[i]){
            int p = e.first;
            int c = e.second;
            update(1,0,N,p,c);
        }
        long long b;
        b = query(1,0,N,k);
        ans += b;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0); cin.sync_with_stdio(0);
    init();
    solve();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值