CF1290C.Prefix Enlightenment
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 A1,…,Ak of 1,2,…,n, such that the intersection of any three subsets is empty. In other words, for all 1≤i1<i2<i3≤k, Ai1∩Ai2∩Ai3=∅.
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 mi 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 mi for all 1≤i≤n.
一条直线上有 n 盏灯,编号从 1 到 n。每盏灯的初始状态为关(0)或开(1)。
给定 k 个集合 A1,…,Ak,它们均为 {1,2,…,n} 的子集,且任意三个集合的交集为空。即,对所有满足 1≤i1<i2<i3≤k 的下标,均有 Ai1∩Ai2∩Ai3=∅。
每次操作中,你可以选择这 k 个集合中的一个,并将其中所有灯的状态翻转(开变关,关变开)。题目保证:在给定这些集合的前提下,总能通过若干次此类操作使所有灯同时处于开启状态。
令 mi 表示使前 i 盏灯(即编号为 1 至 i 的灯)同时开启所需的最少操作次数。注意:对编号在 i+1 到 n 之间的其余灯的状态不作任何要求(可开可关)。
你需要对所有 1≤i≤n,计算出对应的 mi。
输入格式
The first line contains two integers n and k (1≤n,k≤3⋅105).
The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if si=0, on if si=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≤c≤n) — the number of elements in the subset.
The second line of the description contains c distinct integers x1,…,xc (1≤xi≤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.
第一行包含两个整数 n 和 k(1≤n,k≤3⋅105)。
第二行包含一个长度为 n 的二进制字符串,表示每盏灯的初始状态(若 si=0,则第 i 盏灯关闭;若 si=1,则第 i 盏灯开启)。
接下来依次描述 k 个子集,每个子集的描述格式如下:
子集描述的第一行包含一个整数 c(1≤c≤n)—— 表示该子集中元素的个数。
子集描述的第二行包含 c 个互不相同的整数 x1,…,xc(1≤xi≤n)—— 表示该子集的元素。
保证满足以下条件:
- 任意三个子集的交集为空;
- 存在某种操作序列,使得所有灯最终同时处于开启状态。
输出格式
You must output n lines. The i-th line should contain a single integer mi — the minimum number of operations required to make the lamps 1 to i be simultaneously on.
你需要输出 n 行。第 i 行应包含一个整数 mi —— 使灯 1 至 i 同时亮起所需的最少操作次数。
输入输出样例
输入#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=1, we can just apply one operation on A1, the final states will be 1010110;
- For i=2, we can apply operations on A1 and A3, the final states will be 1100110;
- For i≥3, we can apply operations on A1, A2 and A3, the final states will be 1111111.
In the second example:
- For i≤6, we can just apply one operation on A2, the final states will be 11111101;
- For i≥7, we can apply operations on A1,A3,A4,A6, the final states will be 11111111.
在第一个例子中:
- 对于 i=1,我们只需对 A1 执行一次操作,最终状态为 1010110;
- 对于 i=2,我们可对 A1 和 A3 执行操作,最终状态为 1100110;
- 对于 i≥3,我们可对 A1、A2 和 A3 执行操作,最终状态为 1111111。
在第二个例子中:
- 对于 i≤6,我们只需对 A2 执行一次操作,最终状态为 11111101;
- 对于 i≥7,我们可对 A1、A3、A4、A6 执行操作,最终状态为 11111111。
输入解题思路,AI测评打分。不知道怎么写?