Codeforces Round #419 (Div. 2)(B)差分数组
https://www.cnblogs.com/violet-acmer/p/9721160.html
题意:
Karen有n个关于煮咖啡的食谱,每个食谱都有个煮咖啡的最适宜的温度范围,给你 m 个操作,每个操作都是个温度区间,问在此区间内满足条件的温度个数。
需要满足的条件为:在温度 T 时,在n个食谱中查找最宜温度包含T的食谱个数,只有当食谱个数 >= k 时,此温度才算可以计入答案。
题解:
差分数组
AC代码:
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- const int maxn=2e5+;
- int n,k,q;
- int diff[maxn];
- int sum[maxn];
- int need[maxn];
- void init()
- {
- memset(diff,,sizeof(diff));
- memset(sum,,sizeof(sum));
- memset(need,,sizeof(need));
- }
- int main()
- {
- init();
- scanf("%d%d%d",&n,&k,&q);
- int maxP=;
- int minP=;
- for(int i=;i <= n;++i)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- diff[a] += ;
- diff[b+] -= ;
- }
- for(int i=;i < maxn;++i)
- {
- need[i]=need[i-]+diff[i];
- sum[i]=(need[i] >= k ? :)+sum[i-];
- }
- for(int i=;i <= q;++i)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- printf("%d\n",sum[b]-sum[a-]);
- }
- }
Codeforces Round #419 (Div. 2)(B)差分数组的更多相关文章
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 2) A-E
上紫啦! E题1:59压哨提交成功翻盘 (1:00就做完了调了一个小时,还好意思说出来? (逃)) 题面太长就不复制了,但是配图很可爱所以要贴过来 九条可怜酱好可爱呀 A - Karen and Mo ...
- Codeforces Round #419 (Div. 1) 补题 CF 815 A-E
A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...
- Codeforces Round #419 (Div. 2)
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
- Codeforces Round #419 Div. 1
A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...
- Codeforces Round #419 (Div. 2) ABC
python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...
- Codeforces Round #419 (Div. 2) C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
随机推荐
- 最近新明白的SQL小知识
1.partition by和order by 先看三个小需求: ①查询出各个类编号的书本的数量. select count (类编号) as 数量, 类编号 from Books group by ...
- Python_函数_复习_习题_24
# 函数 # 可读性强 复用性强# def 函数名(): # 函数体 #return 返回值# 所有的函数 只定义不调用就一定不执行 #先定义后调用 #函数名() #不接收返回值#返回值 = 函数名( ...
- Junit4使用实验报告
一.题目简介 Junit4的使用及求和测试. 二.源码的github链接 https://github.com/bjing123/test-/blob/master/Arithmetic.txt ht ...
- <构建之法>第11、12章
第11章软件设计与实现 主要讲了典型的开发流程和开发阶段的一些管理方法 问题: 从spec道实现是代码的实现吗? 第12章 用户体验 主要讲了用户体验的各种角度和认识阻力登 问题: 用户的体验是设计前 ...
- 第三个Sprint冲刺第四天(燃尽图)
- js数组的用法
1.数组 - - 添加元素 arr.push('abc') 向数组尾部添加元素,返回值为数组的长度 arr.unshift('abc') 向数组头部添加元素,返回值为数组的长度 2.数组 - - ...
- octave基本指令5
octave基本指令5 控制语句 for >> v=zreos(5,1) v = 0 0 0 0 0 >> for i=1:10, > v(i) = 2^i; > ...
- Install Jetty web server on CentOS 7 / RHEL 7
http://www.eclipse.org/jetty/download.html http://www.eclipse.org/jetty/documentation/current/startu ...
- stratMove方法
/* * elem: 操作哪一个元素 * json:表示多个属性 * attr: 操作的那个元素的css中的什么属性 * value: 操作的那个元素的css中的那个属性的目标值 * cb:回调函数, ...
- linux运维掌握不熟练命令用法记录
rename :批量修改文件名 [root@Dannyserver test]# ls .txt .txt .txt .txt [root@Dannyserver test]# rename 't ...