codeforces round #419 B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee!

Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
3
3
0
4
2 1 1
1 1
200000 200000
90 100
0
In the first test case, Karen knows 3 recipes.
- The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
- The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
- The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
- The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
- The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
题解:
开一个线段树区间修改输入的东西,然后从1扫到200000 如果该位>=k就把该位赋为1
询问就是区间查询
水题,乱搞即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ls (node<<1)
#define rs (node<<1|1)
using namespace std;
const int N=;
int Tree[][N*],mark[][N*];
void updata(bool t,int node){
Tree[t][node]=Tree[t][ls]+Tree[t][rs];
}
void pushdown(bool t,int node)
{
int k=mark[t][node];
mark[t][ls]+=k;mark[t][rs]+=k;
Tree[t][ls]+=k;Tree[t][rs]+=k;
mark[t][node]=;
}
void add(bool t,int l,int r,int node,int sa,int se)
{
if(l>se || r<sa)return ;
if(sa<=l && r<=se)
{
Tree[t][node]++;
mark[t][node]++;
return ;
}
pushdown(t,node);
int mid=(l+r)>>;
add(t,l,mid,ls,sa,se);
add(t,mid+,r,rs,sa,se);
updata(t,node);
}
int getsum(bool t,int l,int r,int node,int sa,int se)
{
if(l>se || r<sa)return ;
if(sa<=l && r<=se)return Tree[t][node];
int mid=(l+r)>>;
pushdown(t,node);
updata(t,node);
return getsum(t,l,mid,ls,sa,se)+getsum(t,mid+,r,rs,sa,se);
}
int main()
{
int n,m,q,x,y,tmp;
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
add(,,,,x,y);
}
for(int i=;i<=;i++)
{
tmp=getsum(,,,,i,i);
if(tmp>=m)add(,,,,i,i);
}
for(int i=;i<=q;i++)
{
scanf("%d%d",&x,&y);
printf("%d\n",getsum(,,,,x,y));
}
return ;
}
codeforces round #419 B. Karen and Coffee的更多相关文章
- Codeforces Round #419 D. Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...
- codeforces round #419 E. Karen and Supermarket
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...
- codeforces round #419 C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- codeforces round #419 A. Karen and Morning
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As yo ...
- 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) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces Round #419 (Div. 2)
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
- Codeforces Round #419 A+B
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes Karen is ...
- Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
随机推荐
- beta冲刺计划安排
经过紧张的Alpha阶段,很多组已经从完全不熟悉语言和环境,到现在能够实现初步的功能.下一阶段即将加快编码进度,完成系统功能.强化软件工程的体会. 凡事预则立,在Beta开始前,以小组为单位,在敏捷冲 ...
- PAT1048. Find Coins(01背包问题动态规划解法)
问题描述: Eva loves to collect coins from all over the universe, including some other planets like Mars. ...
- linux 下 /bin /sbin 的区别
/bin,/sbin,/usr/bin,/usr/sbin区别 / : this is root directory root 用户根目录 /bin : command ...
- 原生JS封装时间运动函数
/*讲时间运动之前先给大家复习一下运动函数 通常大家都会写运动框架,一个定时器(Timer),一个步长(step 就是每次运动的距离),一个当前位置(current)一个目标位置(target),然后 ...
- LDAP apacheds解决方案
Apache DS 配置与管理 LADP基本介绍 LDAP(轻量级目录访问协议)以目录的形式来管理资源(域用户,用户组,地址簿,邮件用户,打印机等等). 特点: 1. LDAP是一种网略协议而 ...
- byte在计算机中的存储方式--Double.byteValue()的输出结果思考
先举三个栗子: 1. public static void main(String[] args) { Double d = new Double(123.56); byte b = d.byteVa ...
- C#Json转DataTable
需求:有一个log文件,需要整理成Excel,日志文件里面的数据都是json字符串 思路是,把Json字符串转换成DataTable,然后导出到Excel 在网上找了一些资料,整理了以下三种类型的Js ...
- NHibernate从入门到精通系列(3)——第一个NHibernate应用程序
内容摘要 准备工作 开发流程 程序开发 一.准备工作 1.1开发环境 开发工具:VS2008以上,我使用的是VS2010 数据库:任意关系型数据库,我使用的是SQL Server 2005 Expre ...
- ccf认证 201709-4 通信网络 java实现
试题编号: 201709-4 试题名称: 通信网络 时间限制: 1.0s 内 ...
- [NOIP2009][LuoguP1073] 最优贸易 - Tarjan,拓扑+DP
Description&Data 题面:https://www.luogu.org/problemnew/show/P1073 Solution Tarjan对联通块缩点,在DAG上按照拓扑序 ...