题干:
链接:https://ac.nowcoder.com/acm/contest/883/A
来源:牛客网
You are given an undirected graph with N\ N N vertices and M\ M M edges. The edges are numbered from 1\ 1 1 to M\ M M . Denote the set S(x)\ S(x) S(x) as: All the vertices we can reach from vertex x\ x x by exactly one edge.
You are supposed to deal with Q\ Q Q operations of the following two types:
Note that all the M\ M M edges are in the graph at the beginning.
The input contains multiple cases. The first line of the input contains a single positive integer T\ T T , the number of cases. For each case, the first line contains two integers N (1≤N≤100000)N\ (1 \leq N \leq 100000)N (1≤N≤100000) and M (1≤M≤200000)M\ (1 \leq M \leq 200000)M (1≤M≤200000), the number of vertices and edges in the graph. In the following M\ M M lines, the i\ i i-th line contains two integers ui,vi (1≤ui,vi≤N)u_i,v_i \ (1 \le u_i,v_i \le N)ui,vi (1≤ui,vi≤N) , describing the the i\ i i-th edge (ui,vi)(u_i,v_i)(ui,vi) . Each edge appears in the input at most once. The (M+2)\ (M+2) (M+2)-th line contains a integer Q (1≤Q≤200000)Q\ (1 \leq Q \leq 200000)Q (1≤Q≤200000) , the number of operations. In the following Q\ Q Q lines, each line contains three integers, describing an operation. The total sum of N\ N N over all cases does not exceed 150000\ 150000 150000. The total sum of M\ M Mover all cases does not exceed 800000\ 800000 800000. The total sum of Q\ Q Q over all cases does not exceed 600000\ 600000 600000.
For each case, print a string in a line. The length of the string should equal the number of operations of type 2\ 2 2. If the answer is yes, the i\ i i-th character of the string should be `1', otherwise it should be `0'. Check the samples for more details.
示例1
复制
1 5 4 1 2 1 3 4 2 4 3 3 2 1 4 1 1 1 2 1 2
复制
10
题目大意:
一个n个点m条边的的图,2种操作:
1 l r 表示从读入的编号为l的边到第r条边,如果有这条边就删掉,否则就加上
2 x y 表示问与点x直接相连的点集是否与y直接相连的点集相同
解题报告:
Hash数组是每个点映射成一个值。
L 和 R 数组对应每个块的左右编号。
O代表单点更新的点的Hash值,laz代表整块的翻转次数的奇偶数。
B数组是预处理数组,在操作的时候不更新,预处理每个块中的每个点向外连边的Hash值。
将输入的边编号然后对边分块,如果要反转的两个区间不在相邻块内或者相同块,那么暴力l块和暴力r块,块间使用laz标记是否翻转。很优秀的想法。
AC代码:
#include
#include
#include
#include
#include
#include