CF1290C.Prefix Enlightenment

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn lamps on a line, numbered from 11 to nn . Each one has an initial state off ( 00 ) or on ( 11 ).

You're given kk subsets A1,,AkA_1, \ldots, A_k of {1,2,,n}\{1, 2, \dots, n\} , such that the intersection of any three subsets is empty. In other words, for all 1i1<i2<i3k1 \le i_1 < i_2 < i_3 \le k , Ai1Ai2Ai3=A_{i_1} \cap A_{i_2} \cap A_{i_3} = \varnothing .

In one operation, you can choose one of these kk 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 mim_i be the minimum number of operations you have to do in order to make the ii first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1i+1 and nn ), they can be either off or on.

You have to compute mim_i for all 1in1 \le i \le n .

输入格式

The first line contains two integers nn and kk ( 1n,k31051 \le n, k \le 3 \cdot 10^5 ).

The second line contains a binary string of length nn , representing the initial state of each lamp (the lamp ii is off if si=0s_i = 0 , on if si=1s_i = 1 ).

The description of each one of the kk subsets follows, in the following format:

The first line of the description contains a single integer cc ( 1cn1 \le c \le n ) — the number of elements in the subset.

The second line of the description contains cc distinct integers x1,,xcx_1, \ldots, x_c ( 1xin1 \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 nn lines. The ii -th line should contain a single integer mim_i — the minimum number of operations required to make the lamps 11 to ii 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

说明/提示

In the first example:

  • For i=1i = 1 , we can just apply one operation on A1A_1 , the final states will be 10101101010110 ;
  • For i=2i = 2 , we can apply operations on A1A_1 and A3A_3 , the final states will be 11001101100110 ;
  • For i3i \ge 3 , we can apply operations on A1A_1 , A2A_2 and A3A_3 , the final states will be 11111111111111 .

In the second example:

  • For i6i \le 6 , we can just apply one operation on A2A_2 , the final states will be 1111110111111101 ;
  • For i7i \ge 7 , we can apply operations on A1,A3,A4,A6A_1, A_3, A_4, A_6 , the final states will be 1111111111111111 .
首页