【codeforces 816B】Karen and Coffee
【题目链接】: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的更多相关文章
- 【codeforces 816C】Karen and Game
[题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全 ...
- 【codeforces 816A】Karen and Morning
[题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如 ...
- 【Codeforces 815C】Karen and Supermarket
Codeforces 815 C 考虑树型dp. \(dp[i][0/1][k]\)表示现在在第i个节点, 父亲节点有没有选用优惠, 这个子树中买k个节点所需要花的最小代价. 然后转移的时候枚举i的一 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- pythone 学习笔记(粗略)
文档目录 概述 安装 基本语法 数据结构 4.1 数字和字符串类型 4.2 元祖 4.3 列表 4.4 字典 流程语句 5.1 分支结构 5.2 逻辑运算符(if) 5.3 循环 5.3.1 for ...
- 小白都能看懂的Linux系统下安装配置Zabbix
实验环境: 操作系统:Centos 7.6 服务器ip:192.168.10.100 运行用户:root 网络环境:Internet Zabbix是一个基于web界面的提供分布式系统监控及网络功能的企 ...
- datalist标签 输入框候选
H5的datalist标签,可以给input输入框提供下拉选择列表,或输入提示功能. 写如下的datalist标签 <datalist id="car"> <op ...
- android startservice无法启动服务
1.android startservice无法启动服务 之前MainActivity.java中启动service源代码如下: private void startMyService() { //启 ...
- maven 构建web项目
Maven规定,必须创建以下几个Source Folder src/main/resources src/main/Java src/test/resources src/test/java 添加以上 ...
- [Python Test] Use pytest fixtures to reduce duplicated code across unit tests
In this lesson, you will learn how to implement pytest fixtures. Many unit tests have the same resou ...
- ant打包和jar包混淆
Ant是一种基于Java的build工具.相似于c语言中的makefile,这里做一记录.方便后面查看. <?xml version="1.0" encoding=" ...
- LeetCode_Maximum Depth of Binary Tree
一.题目 Maximum Depth of Binary Tree My Submissions Given a binary tree, find its maximum depth. The ma ...
- poj 3311 Hie with the Pie (TSP问题)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4491 Accepted: 2376 ...
- PyCharm基本设置、常用快捷键
1. 下载安装 PyCharm官方下载地址: https://www.jetbrains.com/pycharm/download/index.html#section=windows 安装完成后在 ...