CF1677B.Tokitsukaze and Meeting

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Tokitsukaze is arranging a meeting. There are nn rows and mm columns of seats in the meeting hall.

There are exactly n⋅mn \cdot m students attending the meeting, including several naughty students and several serious students. The students are numerated from 11 to n⋅mn\cdot m. The students will enter the meeting hall in order. When the ii-th student enters the meeting hall, he will sit in the 11-st column of the 11-st row, and the students who are already seated will move back one seat. Specifically, the student sitting in the jj-th (1≤j≤m−11\leq j \leq m-1) column of the ii-th row will move to the (j+1)(j+1)-th column of the ii-th row, and the student sitting in mm-th column of the ii-th row will move to the 11-st column of the (i+1)(i+1)-th row.

For example, there is a meeting hall with 22 rows and 22 columns of seats shown as below:

There will be 44 students entering the meeting hall in order, represented as a binary string "1100", of which '0' represents naughty students and '1' represents serious students. The changes of seats in the meeting hall are as follows:

Denote a row or a column good if and only if there is at least one serious student in this row or column. Please predict the number of good rows and columns just after the ii-th student enters the meeting hall, for all ii.

Tokitsukaze 正在组织一场会议。会议厅共有 nn 行 mm 列的座位。

恰好有 n⋅mn \cdot m 名学生参加本次会议,其中包括若干名淘气的学生和若干名认真的学生。学生编号从 11 到 n⋅mn\cdot m。学生们将按编号顺序依次进入会议厅。当第 ii 名学生进入会议厅时,他将坐在第 11 行第 11 列的位置,而已就座的学生则整体向后移动一个座位。具体而言:位于第 ii 行第 jj 列(其中 1≤j≤m−11 \leq j \leq m-1)的学生将移动至第 ii 行第 (j+1)(j+1) 列;而位于第 ii 行第 mm 列的学生将移动至第 (i+1)(i+1) 行第 11 列。

例如,下图展示了一个 22 行 22 列的会议厅:

将有 44 名学生按顺序进入会议厅,其类型用二进制字符串 "1100" 表示,其中 '0' 表示淘气的学生,'1' 表示认真的学生。会议厅座位的变化过程如下所示:

若某一行或某一列中至少存在一名认真的学生,则称该行(或该列)为“好”的。请预测:对每个 ii,在第 ii 名学生进入会议厅之后,会议厅中“好”的行数与“好”的列数分别是多少。

输入格式

The first contains a single positive integer tt (1≤t≤10 0001 \leq t \leq 10\,000) — the number of test cases.

For each test case, the first line contains two integers nn, mm (1≤n,m≤1061 \leq n,m \leq 10^6; 1≤n⋅m≤1061 \leq n \cdot m \leq 10^6), denoting there are nn rows and mm columns of seats in the meeting hall.

The second line contains a binary string ss of length n⋅mn \cdot m, consisting only of zeros and ones. If sis_i equal to '0' represents the ii-th student is a naughty student, and sis_i equal to '1' represents the ii-th student is a serious student.

It is guaranteed that the sum of n⋅mn \cdot m over all test cases does not exceed 10610^6.

第一行包含一个正整数 tt(1≤t≤10 0001 \leq t \leq 10\,000),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 nn、mm(1≤n,m≤1061 \leq n,m \leq 10^6;1≤n⋅m≤1061 \leq n \cdot m \leq 10^6),表示会议厅共有 nn 行 mm 列的座位。

第二行包含一个长度为 n⋅mn \cdot m 的二进制字符串 ss,仅由字符 '0' 和 '1' 组成。若 sis_i 为 '0',表示第 ii 个学生是调皮的学生;若 sis_i 为 '1',表示第 ii 个学生是认真的学生。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 10610^6。

输出格式

For each test case, print a single line with n⋅mn \cdot m integers — the number of good rows and columns just after the ii-th student enters the meeting hall.

对于每个测试用例,输出一行包含 n⋅mn \cdot m 个整数——即第 ii 个学生进入会议室后,此时“好”行与“好”列的数量。

输入输出样例

  • 输入#1

    3
    2 2
    1100
    4 2
    11001101
    2 4
    11001101

    输出#1

    2 3 4 3
    2 3 4 3 5 4 6 5
    2 3 3 3 4 4 4 5

说明/提示

The first test case is shown in the statement.

After the 11-st student enters the meeting hall, there are 22 good rows and columns: the 11-st row and the 11-st column.

After the 22-nd student enters the meeting hall, there are 33 good rows and columns: the 11-st row, the 11-st column and the 22-nd column.

After the 33-rd student enters the meeting hall, the 44 rows and columns are all good.

After the 44-th student enters the meeting hall, there are 33 good rows and columns: the 22-nd row, the 11-st column and the 22-nd column.

第一个测试用例已在题目描述中给出。

在第 11 名学生进入会议室后,有 22 个“好”的行和列:第 11 行和第 11 列。

在第 22 名学生进入会议室后,有 33 个“好”的行和列:第 11 行、第 11 列和第 22 列。

在第 33 名学生进入会议室后,全部 44 行和 44 列均为“好”的行和列。

在第 44 名学生进入会议室后,有 33 个“好”的行和列:第 22 行、第 11 列和第 22 列。

输入解题思路,AI测评打分。不知道怎么写?

首页