CF901C.Bipartite Segments
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. Let's enumerate vertices from 1 to n.
You have to answer q queries. Each query is described by a segment of vertices [l; r], and you have to count the number of its subsegments [x; y] (l ≤ x ≤ y ≤ r), such that if we delete all vertices except the segment of vertices [x; y] (including x and y) and edges between them, the resulting graph is bipartite.
给你一个包含 n 个顶点的无向图。该图中不存在长度为偶数的边简单环(即:不存在长度为偶数、且每条边至多经过一次的环)。我们对顶点从 1 到 n 编号。
你需要回答 q 个查询。每个查询由一个顶点区间 [l,r] 描述,你需要统计其子区间 [x,y](满足 l≤x≤y≤r)的个数,使得:若仅保留顶点区间 [x,y](含端点 x 和 y)内的所有顶点及它们之间的边,则所得子图是二分图。
输入格式
The first line contains two integers n and m (1 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — the number of vertices and the number of edges in the graph.
The next m lines describe edges in the graph. The i-th of these lines contains two integers a__i and b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i), denoting an edge between vertices a__i and b__i. It is guaranteed that this graph does not contain edge-simple cycles of even length.
The next line contains a single integer q (1 ≤ q ≤ 3·105) — the number of queries.
The next q lines contain queries. The i-th of these lines contains two integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ n) — the query parameters.
第一行包含两个整数 n 和 m(1 ≤ n ≤ 3⋅105,1 ≤ m ≤ 3⋅105)—— 分别表示图中的顶点数和边数。
接下来的 m 行描述图中的边。其中第 i 行包含两个整数 ai 和 bi(1 ≤ ai,bi ≤ n;ai = bi),表示顶点 ai 与 bi 之间存在一条边。保证该图不包含长度为偶数的边简单环。
下一行包含一个整数 q(1 ≤ q ≤ 3⋅105)—— 表示查询的数量。
接下来的 q 行包含查询。其中第 i 行包含两个整数 li 和 ri(1 ≤ li ≤ ri ≤ n)—— 表示第 i 个查询的参数。
输出格式
Print q numbers, each in new line: the i-th of them should be the number of subsegments [x; y] (l__i ≤ x ≤ y ≤ r__i), such that the graph that only includes vertices from segment [x; y] and edges between them is bipartite.
输出 q 个数字,每个数字占一行:其中第 i 个数字应表示满足如下条件的子区间 [x; y](即 l__i ≤ x ≤ y ≤ r__i)的个数——仅包含区间 [x; y] 内顶点及其之间边所构成的子图是二分图。
输入输出样例
输入#1
6 6 1 2 2 3 3 1 4 5 5 6 6 4 3 1 3 4 6 1 6
输出#1
5 5 14
输入#2
8 9 1 2 2 3 3 1 4 5 5 6 6 7 7 8 8 4 7 2 3 1 8 1 4 3 8
输出#2
27 8 19
说明/提示
The first example is shown on the picture below:

For the first query, all subsegments of [1; 3], except this segment itself, are suitable.
For the first query, all subsegments of [4; 6], except this segment itself, are suitable.
For the third query, all subsegments of [1; 6] are suitable, except [1; 3], [1; 4], [1; 5], [1; 6], [2; 6], [3; 6], [4; 6].
The second example is shown on the picture below:

第一个示例如下图所示:

对于第一个查询,区间 [1; 3] 的所有子区间(除该区间本身外)均满足条件。
对于第二个查询,区间 [4; 6] 的所有子区间(除该区间本身外)均满足条件。
对于第三个查询,区间 [1; 6] 的所有子区间均满足条件,但以下子区间除外:[1; 3]、[1; 4]、[1; 5]、[1; 6]、[2; 6]、[3; 6]、[4; 6]。
第二个示例如下图所示:

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