【链接】 我是链接,点我呀:)

【题意】

【题解】

我们可以很容易知道区间的每个位置有哪些安排可以用。
显然
我们优先用那些花费的钱比较少的租用cpu方案。
但一个方案可供租用的cpu有限。
我们可以用一个线段树
线段树的下标表示价格。
那一位的值,为这个价格的cpu能租多少个。
弄个区间和(即这个价格的区间总共能租多少个(最多)
再弄另外一个区间和sum表示价格区间内的所有cpu都租,要花多少钱。
因为每个位置最多要租k个cpu
利用上面的两个区间和则我们可以在线段树上做一个二分。
找到租前k个最便宜的cpu要多少钱。(类似平衡树的前k小的和)
(优先价格低的,所以先把左子树选完,如果还不够,再到右子树里面选(左子树直接累加它的价格和就好) )
(如果最后发现l==r,说明当前这个价格l至少有k个,因为你不能多选,所以你恰好选k个就ok
注意线段树的右端点是1e6,而不是n.

【代码】

#include <bits/stdc++.h>
#define ll long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std; const int N = 1e6; ll sc[N*4+10],sum[N*4+10]; vector<pair<int,int> > in[N+10],out[N+10];
int n,k,m,curi; void _updata(int l,int r,int rt,int price,int num){
if (l==r){
sc[rt]+=num;
sum[rt]+=1LL*price*num;
return;
}
int mid = (l+r)>>1;
if (price<=mid)
_updata(lson,price,num);
else
_updata(rson,price,num);
sc[rt]=sc[rt<<1]+sc[rt<<1|1];
sum[rt] = sum[rt<<1]+sum[rt<<1|1];
} ll _query(int l,int r,int rt,int k){
if (k==0) return 0;
if (sc[rt]<=k) return sum[rt];
if (l==r){
return 1LL*k*l;
}
//sc[rt]>k
int mid = (l+r)>>1;
ll temp = 0;
if (sc[rt<<1]<=k) temp+=sum[rt<<1];else return _query(lson,k);
return temp + _query(rson,k-sc[rt<<1]);
} int main(){
#ifdef ccy
freopen("rush.txt","r",stdin);
#endif
scanf("%d%d%d",&n,&k,&m);
rep1(i,1,m){
int x,y,num,p;
scanf("%d%d%d%d",&x,&y,&num,&p);
in[x].push_back(make_pair(num,p));
out[y+1].push_back(make_pair(num,p));
}
ll ans = 0;
rep1(i,1,n){
curi = i;
rep1(j,0,(int) in[i].size()-1){
int num = in[i][j].first,price = in[i][j].second;
_updata(1,N,1,price,num);
}
rep1(j,0,(int) out[i].size()-1){
int num = out[i][j].first,price = out[i][j].second;
_updata(1,N,1,price,-num);
}
ll temp1 = _query(1,N,1,k);
ans += temp1;
}
printf("%lld\n",ans);
return 0;
}

【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  7. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  8. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  9. 2018-2019 ICPC, NEERC, Southern Subregional Contest (codeforces 1070)

    A. 直接从状态(0,0)bfs, 这样一定是最小的 #include <iostream> #include <sstream> #include <algorithm ...

随机推荐

  1. Exchange 2013 的会议室邮箱用户一直无法正常登陆。

    某客户使用了Exchange 2013 server作为邮件承载server.详细版本号为Exchange 2013 SP1. 如今客户有个需求,希望他们的邮箱作为会议室邮箱创建,并且必须有普通邮箱全 ...

  2. vim中凝视多行python代码

    在vim中凝视多行python代码比較麻烦,主要由下面几种方法: (1)将须要凝视的代码以文档字符串的形式呈现 (2)将须要凝视的代码以函数的形式呈现 (3)使用vim自身快捷键 我们主要使用第三种方 ...

  3. Extjs grid 某列点击弹窗

    { header : "单号", tooltip : '单号', dataIndex : 'transportCode', width : 130, sortable : true ...

  4. bootstrap简单form表单样式-form-horizontal

    jsp代码: <div id="content" style="background-color: white;"> <form class= ...

  5. DCloud-MUI:下拉刷新、上拉加载

    ylbtech-DCloud-MUI:下拉刷新.上拉加载 1. 下拉刷新返回顶部 0. http://dev.dcloud.net.cn/mui/pulldown/ 1. 概述 为实现下拉刷新功能,大 ...

  6. Java项目打包发布

    Java项目打包发布 如果只想发布为一个可执行的jar包,使用eclipse的Export功能就可以了 使用eclipse的Export功能,将项目中的所有package打包为一个pet.jar文件, ...

  7. 《疯狂Python讲义》重要笔记——Python简介

    简介 Python是一种面向对象.解释型.弱类型的脚本语言,同时也是一种功能强大的通过语言,它提供了高效的高级数据结构,还有简单有效的面向对象编程. 在大数据.人工智能(AI)领域应用广泛,因此变得流 ...

  8. compare正序与逆序

    //list:在数据查询出来的Record集合 //juli:是需要比较的字段   //实现一个Comparator接口 //后面减去前面是正序   前面减去后面是倒叙 //我这里做的一个距离排序 R ...

  9. Docker EE/Docker CE简介与版本规划

    随着Docker的不断流行与发展,docker公司(或称为组织)也开启了商业化之路,Docker 从 17.03版本之后分为 CE(Community Edition) 和 EE(Enterprise ...

  10. Django 创建新项目后要完成的几个步骤

    首先,在过一遍创建新项目的步骤: -创建一个新项目 -建了数据库后要确定自己是用 mysql数据库  还是用 sqlite3数据库 -如果是mysql数据库,那一堆配置 -如果是sqlite3数据库, ...