1471 线段

1471 线段

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 白银 Silver
 
 
题目描述 Description

有N条线段,已知每条线段的起点和终点(50000以内),然后有M个询问,每次询问一个点(50000以内),求这个点在多少条线段上出现过?

输入描述 Input Description

第一行N线段条数
接下来N行,每行两个数,线段的起点和终点
第N+2行一个数M询问个数
接下来M行,每行一个点

输出描述 Output Description

对于每个询问,求答案

样例输入 Sample Input

3
2 5
4 6
0 7
4
2
4
7
6

样例输出 Sample Output

2
3
1
2

数据范围及提示 Data Size & Hint

N,M<=50000

#include<cstdio>
#include<iostream>
using namespace std;
int a[1001000];
int main(){
    int n,m,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        for(int j=x;j<=y;j++){
            a[j]++;
        }
    }
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&x);
        printf("%d
",a[x]);
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/shenben/p/5516755.html