【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
【链接】 我是链接,点我呀:)
【题意】
【题解】
我们可以很容易知道区间的每个位置有哪些安排可以用。
显然
我们优先用那些花费的钱比较少的租用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的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 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, ...
- 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 ...
- 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$ 思路: 定义一个二元组$< ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (codeforces 1070)
A. 直接从状态(0,0)bfs, 这样一定是最小的 #include <iostream> #include <sstream> #include <algorithm ...
随机推荐
- C# 文件的一些基本操作(转)//用C#读写ini配置文件
C# 文件的一些基本操作 2009-07-19 来自:博客园 字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...
- RMAN异机恢复实验---转载
一.RMAN异机恢复实验 2011年3月23日00:44 1.环境介绍: 主机1: 操作系统 REDHAT5.5 IP地址 172.16.1.120 主机名 sigle 数据库版本 10.2.0.4 ...
- 从map到hash
https://zybuluo.com/ysner/note/1175387 前言 这两种技巧常用于记录和去重量少而分散的状态. 都体现了映射思想. \(map\) 我一般是数组开不下时拿这玩意判重. ...
- bzoj 1800 & 洛谷 P2165 [AHOI2009]飞行棋 —— 模拟
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1800 https://www.luogu.org/problemnew/show/P21 ...
- CSS--浏览器CSS Hack 收集
所谓的Hack就是只有特定浏览器才能识别这段hack代码.Hack 不是什么好东西,除非没有办法,我们尽量还是不要用着玩意. 下面是各个浏览器的CSS Hack 列表. Firefox 浏览器 @-m ...
- JavaScript表格搜索高亮功能模拟
在网页表格中模拟excle的搜索高亮显示功能.当在搜索框中输入需要的姓名时,若表格中存在对应的数据,则该表格背景色变为黄色. 下面为表的HTML源码: <!doctype html> &l ...
- Kubernetes+Jenkins+Nexus+Gitlab进行CI/CD集成
前面已经完成了 二进制部署Kubernetes集群,下面进行CI/CD集成. 一.流程说明 应用构建和发布流程说明: 1.用户向Gitlab提交代码,代码中必须包含Dockerfile: 2.将代码提 ...
- JS通过ajax + 多列布局 + 自动加载来实现瀑布流效果
Ajax 说明:本文效果是无限加载的,意思就是你一直滚动就会一直加载图片出现,通过鼠标滚动距离来判断的,所以不是说的那种加载一次就停了的那种,那种demo下次我会再做一次 css部分用的是html5+ ...
- 使用idea 搭建一个 SpringBoot + Mybatis + logback 的maven 项
(注意项目名不能有大写......),把项目类型 改成 War 类型.(web项目) 使用 mybatis-generator 插件 生成 实体类 和 接口 在 resources 目录 中 新建一个 ...
- SQLServer2008 有用的判断函数
ISNULL(参数1,参数2) 若参数1为空,则返回参数2 NULLIF(参数1,参数2) 若参数1和参数2不等,则返回参数1 若参数1和参数2相等,则返回NULL 例子:ISNULL(NULLIF( ...