Time Limit: 2 second(s) | Memory Limit: 64 MB |
Given n segments (1 dimensional) and q points, for each point you have to find the number of segments which contain that point. A point pi will lie in a segment A B if A ≤ pi ≤ B.
For example, if the segments are (6 12), (8 8), (10 12), (8 11), (0 12) and the point is 11, then it is contained by 4 segments.
Input
Input starts with an integer T (≤ 5), denoting the number of test cases.
Each case starts with a line containing two integers n (1 ≤ n ≤ 50000) and q (1 ≤ q ≤ 50000).
Each of the next n lines contains two integers Ak Bk (0 ≤ Ak ≤ Bk ≤ 108) denoting a segment.
Each of the next q lines contains an integer denoting a point. Each of them range in [0, 108].
Output
For each case, print the case number in a single line. Then for each point, print the number of segments that contain that point.
Sample Input |
Output for Sample Input |
1 5 4 6 12 8 8 10 12 8 11 0 12 11 12 2 20 |
Case 1: 4 3 1 0 |
Notes
Dataset is huge, use faster I/O methods.
题意:
给出 T (<= 5)组数据,后给出 N(1 ~ 50000) 和 Q(1 ~ 50000),代表有 N 个区间和 Q 个数,后给出 N 个区间和 Q 个数的询问,问 Q 这个数被覆盖了多少次,数的范围是 0 ~ 10 ^ 8。
思路:
区间统计 + 离散化。给出 50000 个数,极限情况也就有 3 X 50000 个不同的数,故数组不需要开到 10 ^ 8,只需要开到离散后的极限值就好。区间统计方法是 起点++,(终点 + 1)--,最后统计后一项等于该项 + 前一项的值。最后输出结果即可。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int MAX = 50005 * 3; int l[MAX], r[MAX], ask[MAX]; int num[MAX], res[MAX]; int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; ++tt) { int n, m, ans = 0; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d%d", &l[i], &r[i]); num[ ans++ ] = l[i]; num[ ans++ ] = r[i]; } for (int i = 0; i < m; ++i) { scanf("%d", &ask[i]); num[ ans++ ] = ask[i]; } sort(num, num + ans); ans = unique(num, num + ans) - num; memset(res, 0, sizeof(res)); for (int i = 0; i < n; ++i) { int f = lower_bound(num, num + ans, l[i]) - num; int t = lower_bound(num, num + ans, r[i]) - num; ++res[f]; --res[t + 1]; } for (int i = 0; i < ans; ++i) res[i] += res[i - 1]; printf("Case %d:\n", tt); for (int i = 0; i < m; ++i) { int a = lower_bound(num, num + ans, ask[i]) - num; printf("%d\n", res[a]); } } return 0; }
相关推荐
`LICENSE.txt`包含了项目的开源许可证信息,`.travis.yml`是持续集成工具Travis CI的配置文件,用于自动化测试和构建。 总的来说,这个项目为开发者提供了一个实践Thinkphp6和JWT结合的起点,有助于理解和掌握前后...
vox-5segments.pth.tar
c语言入门 c语言_leetcode题解434-number-of-segments-in-a-string.c
static List[]> GenerateCombinations(int totalWeight, int segments) { List[]> result = new List[]>(); for (int i = 1; i <= totalWeight / segments; i++) { for (int j = 1; j <= totalWeight / ...
无限维Teichmüller空间是复杂分析和几何拓扑领域中的一个高级概念,它是对有限维Teichmüller空间概念的推广。Teichmüller空间在复分析、低维拓扑以及几何学中都扮演着重要的角色。本文由胡韻和沈玉良两位作者撰写...
Nios II 开发常见问题 本文档总结了 Nios II 开发过程中常见的一些问题和解决方法,涵盖了 TCL 脚本、JTAG ID code、ALT_busy_sleep.c 错误、SDK_arm 删除、SOPC 生成错误、Nios II IDE 工程管理、Quartus II 编译...
NIOS II 开发常见问题解答 NIOS II 是 Altera 公司开发的一种基于 FPGA 的嵌入式处理器,广泛应用于数字信号处理、图像处理、网络处理等领域。然而,在 NIOS II 开发过程中,新手经常会遇到一些让人困惑的问题。...
% segments in the result with largest area, and in case less than seven % segments were found, it attempts to recall the function, making the % separation between the already found segments clearer...
segments.gen
资源来自pypi官网。 资源全名:ligo_segments-1.0.1-cp35-cp35m-manylinux1_x86_64.whl
foreach (var point in points.Skip(1)) { var pathFigure = new PathFigure { StartPoint = points.Last() }; var bezierSegment = new BezierSegment { Point1 = new Point(points.Last().X + (point.X - ...
router-segments使用来匹配路由路径, , 和许多其他路由器也使用该路径。 import { createRouterBuilder } from 'router-segments' ; const builder = createRouterBuilder ( ) ; builder . add ( '/' , ref ) ; ...
数据库统计表数据量和条数 在数据库管理中,了解数据库中的表数据量和条数非常重要。不同的数据库管理系统,如MySQL、Oracle和DM(达梦数据库),都提供了不同的方法来统计表数据量和条数。本文将对这些方法进行...
Visifire让你利用ASP、A line chart or line graph is a type of chart which displays information as a series of data points called 'markers' connected by straight line segments.[1] It is a basic type of ...
IMPROVED SPEAKER SEGMENTATION AND SEGMENTS CLUSTERING USING THE BAYESIAN INFORMATION CRITERION(Alain Tritschler and Ramesh Gopinath)
根据提供的文件内容,我们可以整理并深入探讨以下几个与NIOS II相关的技术知识点: ### 1. 如何正确使用TCL脚本进行管脚分配 在使用TCL脚本进行管脚分配时,可能会遇到如下的问题:“`source<pin_assign>.tcl`有点...
- ADD: In TFlexPanel.DefaultLinkPoint property added Size field that lets define visual size of the connection points of the flex-connectors. Initialized with DefaultLinkPointSize constant in the ...