307030: CF1290C. Prefix Enlightenment
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Prefix Enlightenment
题意翻译
给定一个长度为 $n$ 的 01 串 $S$,和 $k$ 个 $S$ 的下标子集,且任意三个子集的交集为空集。一次操作可以选择一个子集,将子集中的下标对应的 $S_i$ 取反。令 $m_i$ 为让 $S_{1 \sim i} = 1$ 的最少操作次数,求出所有的 $m_i$,保证有方案。 $1 \leq n,k \leq 3 \times 10^5$。题目描述
There are $ n $ lamps on a line, numbered from $ 1 $ to $ n $ . Each one has an initial state off ( $ 0 $ ) or on ( $ 1 $ ). You're given $ k $ subsets $ A_1, \ldots, A_k $ of $ \{1, 2, \dots, n\} $ , such that the intersection of any three subsets is empty. In other words, for all $ 1 \le i_1 < i_2 < i_3 \le k $ , $ A_{i_1} \cap A_{i_2} \cap A_{i_3} = \varnothing $ . In one operation, you can choose one of these $ k $ subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation. Let $ m_i $ be the minimum number of operations you have to do in order to make the $ i $ first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between $ i+1 $ and $ n $ ), they can be either off or on. You have to compute $ m_i $ for all $ 1 \le i \le n $ .输入输出格式
输入格式
The first line contains two integers $ n $ and $ k $ ( $ 1 \le n, k \le 3 \cdot 10^5 $ ). The second line contains a binary string of length $ n $ , representing the initial state of each lamp (the lamp $ i $ is off if $ s_i = 0 $ , on if $ s_i = 1 $ ). The description of each one of the $ k $ subsets follows, in the following format: The first line of the description contains a single integer $ c $ ( $ 1 \le c \le n $ ) — the number of elements in the subset. The second line of the description contains $ c $ distinct integers $ x_1, \ldots, x_c $ ( $ 1 \le x_i \le n $ ) — the elements of the subset. It is guaranteed that: - The intersection of any three subsets is empty; - It's possible to make all lamps be simultaneously on using some operations.
输出格式
You must output $ n $ lines. The $ i $ -th line should contain a single integer $ m_i $ — the minimum number of operations required to make the lamps $ 1 $ to $ i $ be simultaneously on.
输入输出样例
输入样例 #1
7 3
0011100
3
1 4 6
3
3 4 7
2
2 3
输出样例 #1
1
2
3
3
3
3
3
输入样例 #2
8 6
00110011
3
1 3 8
5
1 2 5 6 7
2
6 8
2
3 5
2
4 7
1
2
输出样例 #2
1
1
1
1
1
1
4
4
输入样例 #3
5 3
00011
3
1 2 3
1
4
3
3 4 5
输出样例 #3
1
1
1
1
1
输入样例 #4
19 5
1001001001100000110
2
2 3
2
5 6
2
8 9
5
12 13 14 15 16
1
19
输出样例 #4
0
1
1
1
2
2
2
3
3
3
3
4
4
4
4
4
4
4
5