CF369E.Valera and Queries

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera loves segments. He has recently come up with one interesting problem.

The Ox axis of coordinates has n segments, the i-th segment starts in position l__i and ends in position r__i (we will mark it as [l__i, r__i]). Your task is to process m queries, each consists of number cnt__i and a set of cnt__i coordinates of points located on the Ox axis. The answer to the query is the number of segments, such that each of them contains at least one point from the query. Segment [l, r] contains point q, if l ≤ q ≤ r.

Valera found the solution of this problem too difficult. So he asked you to help him. Help Valera.

瓦莱拉喜欢线段。他最近提出了一个有趣的问题。

在坐标系的 OxOx 轴上有 nn 条线段,其中第 ii 条线段起始于位置 lil_i,终止于位置 rir_i(记为 [li, ri][l_i,\,r_i])。你的任务是处理 mm 个查询,每个查询包含一个整数 cnticnt_i 和一组位于 OxOx 轴上的 cnticnt_i 个点的坐标。查询的答案是:满足“该线段至少包含查询中一个点”的线段的数目。线段 [l, r][l,\,r] 包含点 qq,当且仅当 l ≤ q ≤ rl \le q \le r。

瓦莱拉发现这个问题的解法过于困难,因此他请你帮忙。请帮助瓦莱拉。

输入格式

The first line contains two integers n, m (1 ≤ n, m ≤ 3·105) — the number of segments on the axis of coordinates and the number of queries.

Next n lines contain the descriptions of the segments. The i-th line contains two positive integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ 106) — the borders of the i-th segment.

Next m lines contain the description of the queries, one per line. Each line starts from integer cnt__i (1 ≤ cnt__i ≤ 3·105) — the number of points in the i-th query. Then the line contains cnt__i distinct positive integers _p_1, _p_2, ..., p__cnt__i (1 ≤ _p_1 < _p_2 < ... < p__cnt__i ≤ 106) — the coordinates of points in the i-th query.

It is guaranteed that the total number of points in all queries doesn't exceed 3·105.

第一行包含两个整数 nn、mm(1≤n,m≤3⋅1051 \leq n, m \leq 3 \cdot 10^5)—— 分别表示坐标轴上线段的数量和查询的数量。

接下来的 nn 行描述了这些线段。第 ii 行包含两个正整数 lil_i、rir_i(1≤li≤ri≤1061 \leq l_i \leq r_i \leq 10^6)—— 表示第 ii 条线段的左右端点。

接下来的 mm 行描述了各次查询,每行一条。每行首先是一个整数 cnticnt_i(1≤cnti≤3⋅1051 \leq cnt_i \leq 3 \cdot 10^5)—— 表示第 ii 次查询中点的个数;随后是 cnticnt_i 个互不相同的正整数 p1, p2, ..., pcntip_1,\,p_2,\,...,\,p_{cnt_i}(1≤p1<p2<...<pcnti≤1061 \leq p_1 < p_2 < ... < p_{cnt_i} \leq 10^6)—— 表示第 ii 次查询中各点的坐标。

保证所有查询中点的总数不超过 3⋅1053 \cdot 10^5。

输出格式

Print m non-negative integers, where the i-th number is the response to the i-th query.

输出 m 个非负整数,其中第 i 个数为对第 i 个查询的回答。

输入输出样例

  • 输入#1

    3 3
    1 3
    4 5
    6 7
    3 1 4 7
    2 4 5
    1 8

    输出#1

    3
    1
    0

输入解题思路,AI测评打分。不知道怎么写?

首页