CF1093E Intersection of Permutations
题目描述
给定整数 $n$ 和两个 $1,\dots,n$ 的排列 $a,b$。
$m$ 个操作,操作有两种:
- $1\ l_a\ r_a\ l_b\ r_b$,设 $a$ 的 $[l_a;r_a]$ 区间内的元素集合为 $S_a$,设 $b$ 的 $[l_b;r_b]$ 区间内的元素集合为 $S_b$,求 $\lvert S_a \bigcap S_b \rvert$。
- $2\ x\ y$,交换 $b$ 的第 $x$ 位与第 $y$ 位。
$1 \le n,m \le 2 \cdot 10^5$
输入格式
第一行,两个整数 $n,m$。
以下两行,每行 $n$ 个整数,分别表示 $a,b$。
以下 $m$ 行,每行一个操作。
输出格式
对于每个 $1$ 操作,输出答案。
说明/提示
Consider the first query of the first example. Values on positions $ [1; 2] $ of $ a $ are $ [5, 1] $ and values on positions $ [4; 5] $ of $ b $ are $ [1, 4] $ . Only value $ 1 $ appears in both segments.
After the first swap (the second query) permutation $ b $ becomes $ [2, 1, 3, 5, 4, 6] $ .
After the second swap (the sixth query) permutation $ b $ becomes $ [5, 1, 3, 2, 4, 6] $ .