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

【题解】

我们可以很容易知道区间的每个位置有哪些安排可以用。
显然
我们优先用那些花费的钱比较少的租用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]>kint 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 ccyfreopen("rush.txt","r",stdin);#endifscanf("%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;
}

转载于:https://www.cnblogs.com/AWCXV/p/9932869.html

【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing相关推荐

  1. [CodeForces1070C]Cloud Computing(2018-2019 ICPC, NEERC, Southern Subregional Contest )

    传送门:戳我 在cf上做的镜像赛,结果不是很妙啊.. 这题是用时最长但并没有在比赛内写出来(事实上在赛后还话了大概五小时调试才找出错误) 首先不难发现我们需要一棵线段树,(其实一开始我考虑的是主席树) ...

  2. Codeforces 1070A Find a Number(BFS) 2018-2019 ICPC, NEERC, Southern Subregional Contest Problem A

    Description You are given two positive integers ddd and sss. Find minimal positive integer nnn which ...

  3. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest

    A. Automatic Door 对于规律的点可以推公式计算,对于噪点则暴力计算,时间复杂度$O(m\log m)$. #include<stdio.h> #include<ios ...

  4. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题

    Problem D. Grumpy Cat 题目连接: http://www.codeforces.com/gym/100253 Description This problem is a littl ...

  5. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem C. Equivalent Cards 计算几何

    Problem C. Equivalent Cards 题目连接: http://www.codeforces.com/gym/100253 Description Jane is playing a ...

  6. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem I. Plugs and Sockets 费用流

    Problem I. Plugs and Sockets 题目连接: http://www.codeforces.com/gym/100253 Description The Berland Regi ...

  7. The 2019 ICPC Asia Shanghai Regional Contest

    The 2019 ICPC Asia Shanghai Regional Contest 题号 题目 知识点 A Mr. Panda and Dominoes B Prefix Code C Maze ...

  8. 【GYM101409】2010-2011 ACM-ICPC, NEERC, Western Subregional Contest

    A-Area and Circumference 题目大意:在平面上给出$N$个三角形,问周长和面积比的最大值. #include <iostream> #include <algo ...

  9. Replay:The 2019 ICPC Asia-East Continent Final Contest (Training)

    A B C D E F G H I J K L M 2019 EC FINAL (2020/9/9) ⭕ ✔ ⭕ ✔ ⭕ ✔ ⭕ ✔ ⭕ Replay: A solved by sanshuiii. ...

最新文章

  1. 深度剖析WinPcap之(二)——网络分析与嗅探的基础知识(1)
  2. 使用idea编写SparkStreaming消费kafka中的数据【小案例】(四)
  3. Moonlight已经可以下载,目前是0.6版
  4. 盘点和程序员相关的那些事,让你不再被割韭菜,薅羊毛!
  5. bzoj 4372 烁烁的游戏 —— 动态点分治+树状数组
  6. python基础知识7——迭代器,生成器,装饰器
  7. [CODEVS1911] 孤岛营救问题(分层图最短路)
  8. 1. ansible-playbook 变量定义与引用
  9. 改善C#程序的建议9:使用Task代替ThreadPool和Thread
  10. 微信如何添加企业微信信息服务器地址,企业微信和微信消息怎么互通_企业微信和微信消息互通操作流程一览...
  11. 用border-color 的 transparent 制作一个三角形
  12. UBT18:ubuntu安装阿里云盘
  13. 软件项目量化管理(CMMI高成熟度)实践经验谈——之项目管理过程监督与控制篇
  14. JavaScript使用url字符串拼接传递参数,截取参数
  15. 二十一世纪“新元宇宙”奇科幻小说原创作品系列连载【第一部】第二回 登峰时刻
  16. ElasticSearch学习(四)—— 中文按拼音排序拼音检索
  17. 读Applying Deep Learning To Airbnb Search有感
  18. 管理信息系统【四】之 管理信息系统战略规划与开发方法
  19. [人工智能-深度学习-59]:生成对抗网络GAN - 基本原理(图解、详解、通俗易懂)
  20. 从事资本运作的人应该具备的操守

热门文章

  1. class-5 If语句
  2. 40个比较重要的Android面试题
  3. 开源Math.NET基础数学类库使用(11)C#计算相关系数
  4. Exists and IN
  5. MySQL中的配置参数interactive_timeout和wait_timeout
  6. 蓝桥杯比赛常考算法_蓝桥杯总结-常用函数及算法
  7. Unix/Linux常用命令及配置
  8. OVS datapath简介(十八)
  9. idea spring 中没有标识_Spring 优雅的国际化实现
  10. python parser count_Python分析哪座城市小吃最好吃