【题目链接】:http://codeforces.com/contest/816/problem/B

【题意】



给你很多个区间[l,r];

1<=l<=r<=2e5

一个数字如果被k个以上的区间覆盖到;

则称之为特殊数字;

给你q个询问区间;

问你这q个区间里面

每个区间里面有多少个特殊数字;

【题解】



对于覆盖的区间l,r

add[l]++,sub[r+1]++,

然后顺序枚举

now+=add[i];

now-=sub[i];

如果now>=k则i是一个特殊数字;

写个前缀和O(1)输出答案.



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; int add[N],sub[N],n,k,q;
int is[N],sum[N]; int main(){
//Open();
Close();
cin >> n >> k >> q;
rep1(i,1,n){
int x,y;
cin >> x >> y;
add[x]++,sub[y+1]++;
}
int now = 0;
rep1(i,1,(int) 2e5){
now+=add[i];
now-=sub[i];
if (now>=k){
is[i] = 1;
}
}
sum[0] = 0;
rep1(i,1,(int) 2e5){
sum[i] = sum[i-1] + is[i];
}
rep1(i,1,q){
int x,y;
cin >> x >> y;
cout << sum[y]-sum[x-1] << endl;
}
return 0;
}

【codeforces 816B】Karen and Coffee的更多相关文章

  1. 【codeforces 816C】Karen and Game

    [题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全 ...

  2. 【codeforces 816A】Karen and Morning

    [题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如 ...

  3. 【Codeforces 815C】Karen and Supermarket

    Codeforces 815 C 考虑树型dp. \(dp[i][0/1][k]\)表示现在在第i个节点, 父亲节点有没有选用优惠, 这个子树中买k个节点所需要花的最小代价. 然后转移的时候枚举i的一 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. Linux版本分支图

  2. Vue -- 只弹一次的弹框

    核心代码是 getCookie()部分,控制弹框的显示隐藏则在 created()中. <template> <div v-if="isShow"> < ...

  3. Python 绘图与可视化 matplotlib 制作Gif动图

    参考链接:https://blog.csdn.net/theonegis/article/details/51037850 官方文档:https://matplotlib.org/3.1.0/api/ ...

  4. 2019-03-18 使用Request POST获取CNABS网站上JSON格式的表格数据,并解析出来用pymssql写到SQL Server中

    import requests import pymssql url = 'https://v1.cn-abs.com/ajax/ChartMarketHandler.ashx' headers = ...

  5. linux文件与用户和群组

    文件基本属性 在图片中alogrithm的文件属性为drwxrwxr-x,其中d代表此文件为目录. 后面rwx,rwx,r-x分别代表文件所属者(ower),组(group),其他用户(other)的 ...

  6. 少年 DXH

    少年 DXH 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 大家都知道,DXH 幼时性格怪癖,小朋友都不喜欢和他玩,这样的情况一直到 DXH 的少年时期也没有改变. ...

  7. Apache shiro 笔记整理之编程式授权

    下面内容是在看了涛哥的<跟我一起学shiro> 和 视频<一头扎入进shiro> 后整理出来备忘和方便自己和其它人学习. 个人主页:http://www.itit123.cn/ ...

  8. linux下线程

    linux下线程 线程与进程的关系: 之前转载的微信文章,进程与线程的差别已经说得比較清楚了.能够查看之前转载的文章.linux进程与线程的差别. 创建一个线程: #include<pthrea ...

  9. 数据库中的java.sql.Timestamp转换成Date

    查询数据库中的时间类型为 java.sql.Timestamp 保存在json中需要格式化 自定义工具类  DateJsonValueProcessor package com.rom.util; i ...

  10. 详解JSP九个内置对象

    [JSP]☆★之详解九个内置对象       在web开发中,为方便开发者,JSP定义了一些由JSP容器实现和管理的内置对象,这些对象可以直接被开发者使用,而不需要再对其进行实例化!本文详解,JSP2 ...