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 ...
随机推荐
- #个人博客作业week3——微软必应词典的使用
产品的调研和评测 笔者使用的是win8的必应词典客户端. 首先打开客户端,用户界面的设计十分简洁,使用方便.但是词典主页与大多外语软件的设计相仿,例如有每日一句,每日阅读等模块,并没有令人感到新奇的地 ...
- linux第二次读书笔记
<Linux内核设计与实现>读书笔记 第五章 系统调用 第五章系统调用 系统调用是用户进程与内核进行交互的接口.为了保护系统稳定可靠,避免应用程序恣意忘形. 5.1与内核通信 系统调用 ...
- github 心得体会
https://github.com/xu123/text 学习了很多知识感觉很有趣 git config :配置git git add:更新working directory中的文件至stagin ...
- Java面向对象(Eclipse高级、类与接口作为参数返回值)
面向对象 今日内容介绍 u Eclipse常用快捷键操作 u Eclipse文档注释导出帮助文档 u Eclipse项目的jar包导出与使用jar包 u 不同修饰符混合使用细节 u 辨析何时定义变 ...
- Running kubernetes on windows
docker-for-desktop minikube GKE cluster(?) docker-for-desktop https://docs.docker.com/docker-for-win ...
- 8 commands to check cpu information on Linux
https://www.binarytides.com/linux-cpu-information/
- [CB]2018全球半导体营收4700亿美元 三星继续碾压英特尔
2018全球半导体营收4700亿美元 三星继续碾压英特尔 https://www.cnbeta.com/articles/tech/808833.htm Gartner最新报告显示,2018年全球半导 ...
- hive启动方式
- mysql学习笔记四 —— AB复制
要点:ab复制 mysql集群架构流程: ABB(主从复制)-->MHA(实现mysql高可用.读写分离.脚本控制vip飘逸)-->haproxy(对slave集群实现分发,负载均衡)-- ...
- rabbitmq代码配置
package com.qukoucai.test; import com.rabbitmq.client.AMQP;import com.rabbitmq.client.AMQP.BasicProp ...