CF2020D Connect the Dots

题目描述

### 题意描述 Alice画了一条直线,并在上面标记了 $n$ 个点,从 $1$ 到 $n$ 进行索引。最初,点之间没有连边,所以它们都是不连通的。之后,Alice执行以下类型的 $m$ 个操作: 1. 她选了三个整数 $a_i , d_i , k_i , (1 \le d_i \le 10)$ 2. 她选择点 $a_i,a_i+d_i,a_i+2d_i......a_i+k_i \times d_i$,并在每对点之间连边。 在完成所有的 $m$ 次操作后,她想知道这些点形成的连接组件的数量。 如果两个点之间通过几条(**可能为零**)边和其他点存在路径,则称这两个点位于一个连通块中。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$ 。每个测试用例的描述如下: 每个测试用例的第一行包含两个整数 $n$ 和 $m$ 。 以下 $m$ 行中的第 $i$ 行包含三个整数 $a_i , d_i , k_i , (1 \le a_i \le a_i+k_i⋅d_i \le n, 1 \le d_i \le 10, 0 \le k_i \le n) $ 。 保证所有测试用例中的 $n$ 和 $m$ 之和不超过 $2\times 10^5$。

输出格式

对于每个测试用例,输出联通块数量。

说明/提示

In the first test case, there are $ n = 10 $ points. The first operation joins the points $ 1 $ , $ 3 $ , $ 5 $ , $ 7 $ , and $ 9 $ . The second operation joins the points $ 2 $ , $ 4 $ , $ 6 $ , $ 8 $ , and $ 10 $ . There are thus two connected components: $ \{1, 3, 5, 7, 9\} $ and $ \{2, 4, 6, 8, 10\} $ . In the second test case, there are $ n = 100 $ points. The only operation joins the points $ 19 $ , $ 21 $ , $ 23 $ , $ 25 $ , and $ 27 $ . Now all of them form a single connected component of size $ 5 $ . The other $ 95 $ points form single-point connected components. Thus, the answer is $ 1 + 95 = 96 $ . In the third test case, there are $ n = 100 $ points. After the operations, all odd points from $ 1 $ to $ 79 $ will be in one connected component of size $ 40 $ . The other $ 60 $ points form single-point connected components. Thus, the answer is $ 1 + 60 = 61 $ .