二分加贪心,水过了。贪心是因为,不能存在覆盖,当存在覆盖时,留小坐标的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 300100
using namespace std; struct Point{
int left,right;
}pl[N]; int query[N/3][2]; bool cmp(Point a,Point b){
if(a.right<b.right)
return true;
return false;
} int find_index(int a,int n){
int l=0; int r=n-1;
int ans=-1;
while(l<=r){
int mid=(l+r)/2;
if(pl[mid].right<=a){
ans=mid;
l=mid+1;
}
else r=mid-1;
}
return ans;
} int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=0;i<n;i++)
scanf("%d%d",&pl[i].left,&pl[i].right);
for(int i=1;i<=m;i++){
scanf("%d%d",&query[i][0],&query[i][1]);
}
sort(pl,pl+n,cmp);
for(int i=1;i<=m;i++){
int a=query[i][0],b=query[i][1];
int bgn=find_index(a,n);
int ans=0;
int pos=a;
for(int k=bgn+1;k<n;k++){
if(pl[k].right<=b){
if(pl[k].left>=pos){
ans++;
pos=pl[k].right;
}
}
else break;
}
printf("%d\n",ans);
}
}
return 0;
}

  

HDU 4343的更多相关文章

  1. HDU 4343 贪心

    D - Interval queryTime Limit: 1.5 Sec Memory Limit: 256 MB Description This is a very simple questio ...

  2. HDU 4343 D - Interval query 二分贪心

    D - Interval queryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  3. 【HDU 4343】Interval query(倍增)

    BUPT2017 wintertraining(15) #8D 题意 给你x轴上的N个线段,M次查询,每次问你[l,r]区间里最多有多少个不相交的线段.(0<N, M<=100000) 限 ...

  4. HDU 4343 Interval query(贪心 + 倍增)

    题目链接  2012多校5 Problem D 题意  给定$n$个区间,数字范围在$[0, 10^{9}]$之间,保证左端点严格大于右端点. 然后有$m$个询问,每个询问也为一个区间,数字范围在$[ ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Intel Media SDK安装步骤

    !!!(gcc/g++版本要在4.8以上,本人使用的是5.4版本) 要先安装依赖,按以下步骤依次执行 1.LIBVA git clone https://github.com/intel/libva. ...

  2. Swift3.0 split函数切割字符串

    我们先看函数的原型: public func split(separator: Self.Iterator.Element, maxSplits: Int = default, omittingEmp ...

  3. [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)

    interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...

  4. 什么是Ajax和JSON,他们的优缺点?

    ajax的概念:ajax是一种通过后台与服务器进行少量的数据交换,实现页面异步更新 是一种创建交互式网页应用的网页开发技术. json的概念:json是一种轻量级的数据交换格式,具有良好的可读和便于快 ...

  5. Irrlicht 1.8.4 + Win7 + VC2015 + x64 +OpenGL编译

    1. 下载irrlicht1.8.4 https://nchc.dl.sourceforge.net/project/irrlicht/Irrlicht%20SDK/1.8/1.8.4/irrlich ...

  6. LeetCode Weekly Contest 21

    1. 530. Minimum Absolute Difference in BST 最小的差一定发生在有序数组的相邻两个数之间,所以对每一个数,找他的前驱和后继,更新结果即可!再仔细一想,bst的中 ...

  7. jumpserver install

    本文来源jumpserver官网 一步一步安装 环境 系统: CentOS 7 IP: 192.168.244.144 关闭 selinux 和防火墙 # CentOS 7 $ setenforce ...

  8. listview 控件

    private void Form1_Load(object sender, EventArgs e) { //设置该listview关联的imagelist listView1.LargeImage ...

  9. P1732 活蹦乱跳的香穗子

    题目描述 香穗子在田野上调蘑菇!她跳啊跳,发现自己很无聊,于是她想了一个有趣的事情,每个格子最多只能经过1次,且每个格子都有其价值 跳的规则是这样的,香穗子可以向上下左右四个方向跳到相邻的格子,并且她 ...

  10. 还是UVa340

    #include<stdio.h> #define maxn 1010 int main() { int num,a[maxn],i,j,b[maxn]; ; &&num) ...