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

【题意】

【题解】

我们可以很容易知道区间的每个位置有哪些安排可以用。
显然
我们优先用那些花费的钱比较少的租用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. vim中凝视多行python代码

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

  2. iOS:在UITextField中加入图标

    //最左側加图片是下面代码 右側相似 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&q ...

  3. visual studio2013 C++查看对象布局

    一在visual studio中进行设置,可以方便的查看对象的内存布局 右键所要显示的*.cpp >> 属性 >> 命令行 >> 其它选项 在其他选项中添加: /d ...

  4. oc34--instancetype和id的区别

    // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject @property int age; ...

  5. linux中两个缓冲区

    不同于Windows,Linux系统里存在两个剪切板:一个叫做选择缓冲区(X11 selection buffer),另一个才是剪切板(clipboard). 01)选择缓冲区(缓冲内容在其他位置可用 ...

  6. 学习笔记二十三——字符函数库cctype【转】

    本文转载自: 字符函数库cctype 在头文件cctype(ctype.h)中定义了一些函数原型,可以简化输入确定字符是否为大写字母.数字.标点符号等工作. 例如: 如果ch是一个字母,则isalph ...

  7. Mybatis 碰到的一些问题

    1. SQL语句参数无法获取:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no get ...

  8. Python 36 死锁现象和递归锁、信号量、Event事件、线程queue

    一:死锁现象和递归锁 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远 ...

  9. BN 详解和使用Tensorflow实现(参数理解)

    Tensorflow   BN具体实现(多种方式): 理论知识(参照大佬):https://blog.csdn.net/hjimce/article/details/50866313 补充知识: ① ...

  10. POJ 3114 Tarjan+Dijkstra

    题意: 间谍在战争期间想要传递一份谍报回国,谍报可以在邮局之间传递,但这种传递是单向的,并且会少耗一些时间.但是如果两个邮局在同一个国家的话,那么谍报在这两个邮局之间传递是不消耗时间的.如果几个邮局发 ...