CF816B-Karen and Coffee

2023-05-16

B. Karen and Coffee

time limit per test2.5 seconds 
memory limit per test512 megabytes 
inputstandard input 
outputstandard output 
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?

Input 
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.

Output 
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.

Examples 
input 
3 2 4 
91 94 
92 97 
97 99 
92 94 
93 97 
95 96 
90 100 
output 




input 
2 1 1 
1 1 
200000 200000 
90 100 
output 

0


题意: 给出n个配料区间,q个查询区间,问每次查询时,该查询区间内有多少个点至少被k个配料区间覆盖。

思路: 区间标记和查询, 用了一个树状数组优化,跑了200ms。

上代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[200010];
int tmp[200010];
int getf(int x)
{
    return x&(-x);
}
void add_ans(int x,int d)
{
    while(x<200010)
    {
        ans[x] += d;
        x += getf(x);
    }
    return ;
}
int get_sum_ans(int x)
{
    int sum = 0;
    while(x>0)
    {
        sum += ans[x];
        x -= getf(x);
    }
    return sum;
}
int main()
{

  int n,k,q;
  int a,b;
  while(scanf("%d%d%d", &n,&k,&q) != EOF)
  {
  memset(ans, 0,sizeof(ans));
  memset(tmp, 0,sizeof(tmp));

  for(int i=1; i<=n; i++)
  {
      scanf("%d %d",&a,&b);
      add_ans(a,1);
      add_ans(b+1,-1);
  }
  for(int i=1; i<=200005; i++)
  {
      int p = get_sum_ans(i);
      if(p>=k) tmp[i] = tmp[i-1]+1;
      else tmp[i] = tmp[i-1];
  }
  for(int i=1; i<=q; i++)
  {
      scanf("%d%d",&a,&b);
      printf("%d\n",tmp[b]-tmp[a-1]);
  }


  }
   return 0;
}

水波。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CF816B-Karen and Coffee 的相关文章

随机推荐

  • 关于Xray中代理的一些总结

    在Xray使用的时候遇到了一些代理问题 在一般的扫描中 为了出现意外情况 可能会封ip或者扫描崩掉 会用代理扫描网站 xff1a 1 第一种办法就是直接在 config yaml 中直接修改代理ip xff0c 我这里是将代理改为burp的
  • Angular:formGroup中嵌套formArray,在formArray中存放的可编辑table中的字段的动态展示

    今天做的项目中做了一个新增页面 xff0c 其中最顶级是一个formGroup表单命名为editClauseForm xff0c 里面有几个单独的字段 xff0c 还有一个嵌套的formArray xff0c 命名为clauseArr xf
  • 【Java系列-6】Java实现:有1、2、3、4这4个数字,能组成多少个互不相同且无重复数字的三位数、都是多少

    Java系列 6 Java实现 xff1a 有1 2 3 4这4个数字 xff0c 能组成多少个互不相同且无重复数字的三位数 xff1f 都是多少 xff1f 1 问题 Java实现 xff1a 有1 2 3 4这4个数字 xff0c 能组
  • 【C、C++系列-10】C语言实现:百钱买百鸡问题

    C C 43 43 系列 10 C语言实现 xff1a 百钱买百鸡问题 1 问题 百钱买百鸡问题 xff1a 我国古代数学家张丘建在 算经 一书中曾提出过著名的 百钱买百鸡 问题 该问题叙述如下 xff1a 鸡翁一 xff0c 值钱五 xf
  • Android 通知使用权

    1 创建service extends NotificationListenerService xff0c 并实现onNotificationRemoved onNotificationPosted public class Notific
  • Android 系统文件浏览器

    1 调用系统文件浏览器 Intent intent 61 new Intent Intent ACTION GET CONTENT intent setType 34 34 设置类型 xff0c 我这里是任意类型 xff0c 任意后缀的可以
  • Android 导入导出excel xls、xlsx

    1 导入依赖 implementation group 39 org apache poi 39 name 39 poi ooxml 39 version 39 3 17 39 implementation group 39 org apa
  • Android 导出PDF PdfDocument

    导出PDF 64 param view 要导出的view xff0c 如果view高度过高 xff08 超过一屏的高度 xff09 xff0c 在改view外部套一层Scrollview即可 如果要导出列表类型View 比如Listview
  • Android 获取所有短信-彩信

    1 权限 lt 读取短信 gt lt uses permission android name 61 34 android permission READ SMS 34 gt lt uses permission android name
  • Photoshop CC 2018 安装包安装教程

    Photoshop CC 2018功能特点 1 更紧密连接的 Photoshop 全新的智慧型锐利化 2 智慧型增加取样 内含 Extended 功能 Camera RAW 8 和图层支援 3 可编辑的圆角矩形 多重形状和路径选择 相机防手
  • 【原创】什么是原码、反码、补码?

    原码 反码 补码是计算机中对数字的二进制表示方法 原码 xff1a 将最高位作为符号位 xff08 0表示正 xff0c 1表示负 xff09 xff0c 其它数字位代表数值本身的绝对值的数字表示方式 反码 xff1a 如果是正数 xff0
  • snprintf中的错误,不要出现目标地址也是源地址的情况

    在使用snprintf时 xff0c 千万要注意一点 xff0c 不要出现目标地址也是源地址的情况 看如下例子 xff1a span class token macro property span class token directive
  • Linux下的shell进度条

    一 关于Shell Shell的作用是解释执行用户的命令 xff0c 它有两种执行命令的方式 xff1a 交互式和批处理 Shell脚本和编程语言很相似 xff0c 也有变量和流控制语句 xff0c 但Shell脚本是解释执行 xff0c
  • you-get相关使用命令

    you get i url 获取视频格式 清晰度等信息 you get o E folder url 保存路径 在当前目录的路径栏 输入cmd即可打开命令行 或者 shift 右键 用powershell打开 you get p PotPl
  • Spring Cloud从入门到放弃(四):Eureka的常用配置

    前言 Spring Cloud系列 点击查看Spring Cloud系列文章 eurka的常用配置 eureka server前缀的配置项 是否允许开启自我保护模式 xff0c 缺省 xff1a span class token boole
  • STM32之点亮LED

    学习一个新的处理器 xff0c 第一个程序肯定就是点亮LED xff0c 它可以让我们较快的 较清晰的了解到一个处理器的程序结构 xff0c 学习32也不例外 xff0c 首先第一个程序我们就来点亮LED xff0c 点亮LED程序有很多种
  • 判断两条线段是否相交

    判断两条直线是否相交有两步 xff1a 1 xff1a 快速排斥 xff08 可以筛除大部分 xff09 2 xff1a 跨立试验 xff08 下面会有所说明 xff09 现在开始解释 xff1a 第一步快速排斥 xff0c 实际上就是先判
  • 2015-2016 ACM-ICPC Pacific Northwest Regional Contest Div.2( Problem V Gears)

    题目地址 xff1a 点击打开链接 题意 xff1a 给你很多齿轮 xff0c 让你判断第一个齿轮和第n个齿轮的关系 有三种关系题目中已经给出 解题思路 xff1a 算是比较直观的一个dfs题目了 xff0c 重点是怎么样处理这个dfs 结
  • 免费馅饼(简单动态规划)

    都说天上不会掉馅饼 xff0c 但有一天gameboy正走在回家的小径上 xff0c 忽然天上掉下大把大把的馅饼 说来gameboy的人品实在是太好了 xff0c 这馅饼别处都不掉 xff0c 就掉落在他身旁的10米范围内 馅饼如果掉在了地
  • CF816B-Karen and Coffee

    B Karen and Coffee time limit per test2 5 seconds memory limit per test512 megabytes inputstandard input outputstandard