309081: CF1621E. New School

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

New School

题意翻译

你决定开办一所新学校,并且你已经找到了 $n$ 个老师和 $m$ 组学生,其中,第 $i$ 组学生包含 $k_i$ 个学生。第 $i$ 个老师的编号为 $i$,第 $i$ 组学生中的第 $j$ 个学生的编号为 $(\sum\limits_{x=1}^{i-1} k_x)+j$。 你已经知道了每个老师和同学的年龄,其中第 $i$ 个老师的年龄为 $a_i$,第 $i$ 组学生中的第 $j$ 个学生的年龄为 $b_{i,j}$。为了能够顺利开课,你需要安排每个老师和每组学生进行组合。这样的安排必须满足如下条件: - 一组学生和**恰好一个**老师组合。 - 一个老师和**至多一组**学生组合。 - 每个组合中,所有该组学生的年龄的平均值不能够超过老师的年龄。 最近你听到有一个学生退学了,但是由于你听力不好,你并没有听清这个学生的编号。你知道有学生退学会使得该组学生的人数减 $1$,该组的年龄平均值也会因此受到影响,进而会影响到学校的顺利开课。于是,对于 $[1,\sum\limits_{i=1}^m k_i]$ 中的所有整数 $x$,你想知道如果编号为 $x$ 的学生退学,学校是否还能够顺利开课。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 1000$。 - $1\leqslant m\leqslant n\leqslant 10^5$,$\sum n\leqslant 10^5$。 - $1\leqslant a_i,b_{i,j}\leqslant 10^5$,$2\leqslant k_i\leqslant 10^5$,$\sum\limits_{i=1}^m k_i\leqslant 2\times 10^5$。 Translated by Eason_AC 2022.1.4

题目描述

You have decided to open a new school. You have already found $ n $ teachers and $ m $ groups of students. The $ i $ -th group of students consists of $ k_i \geq 2 $ students. You know age of each teacher and each student. The ages of teachers are $ a_1, a_2, \ldots, a_n $ and the ages of students of the $ i $ -th group are $ b_{i, 1}, b_{i, 2}, \ldots, b_{i, k_i} $ . To start lessons you should assign the teacher to each group of students. Such assignment should satisfy the following requirements: - To each group exactly one teacher assigned. - To each teacher at most $ 1 $ group of students assigned. - The average of students' ages in each group doesn't exceed the age of the teacher assigned to this group. The average of set $ x_1, x_2, \ldots, x_k $ of $ k $ integers is $ \frac{x_1 + x_2 + \ldots + x_k}{k} $ . Recently you have heard that one of the students will refuse to study in your school. After this, the size of one group will decrease by $ 1 $ while all other groups will remain unchanged. You don't know who will refuse to study. For each student determine if you can start lessons in case of his refusal. Note, that it is not guaranteed that it is possible to start lessons before any refusal.

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \leq t \leq 1000 $ ) — the number of test cases. The first line of each test case contains two integers $ n $ and $ m $ ( $ 1 \leq m \leq n \leq 10^5 $ ) — the number of teachers and the number of groups of students. The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \leq a_i \leq 10^5 $ ) — the ages of teachers. The next $ 2m $ lines contains descriptions of groups. The first line of description of group contains a single integer $ k_i $ ( $ 2 \leq k_i \leq 10^5 $ ) — the number of students in this group. The second line of description of group contains $ k_i $ integers $ b_{i, 1}, b_{i, 2}, \ldots, b_{i, k_i} $ ( $ 1 \leq b_{i, j} \leq 10^5 $ ) — the ages of students of this group. It is guaranteed that the total sum of $ n $ over all test cases doesn't exceed $ 10^5 $ and that the total sum of $ k_1 + k_2 + \ldots + k_m $ over all test cases doesn't exceed $ 2 \cdot 10^5 $

输出格式


For each test case output string of symbols $ 0 $ and $ 1 $ of length $ k_1 + k_2 + \ldots + k_m $ . The $ i $ -th symbol of this string should be equals $ 1 $ if it is possible to start lessons in case of the $ i $ -th student refuse and it should be equals $ 0 $ otherwise. Students are numbered by integers from $ 1 $ to $ k_1 + k_2 + \ldots + k_m $ in the order they appear in the input. Thus, students of the $ 1 $ -st group are numbered by integers $ 1 $ , $ 2 $ , $ \ldots $ , $ k_1 $ , students of the $ 2 $ -nd group are numbered by integers $ k_1 + 1 $ , $ k_1 + 2 $ , $ \ldots $ , $ k_1 + k_2 $ and so on.

输入输出样例

输入样例 #1

2
1 1
30
3
25 16 37
4 2
9 12 12 6
2
4 5
3
111 11 11

输出样例 #1

101
00100

说明

In the first test case there is one group of students with average age $ \frac{25+16+37}{3}=26 $ and one teacher with age $ 30 $ . There exists only one assignment that allows to start lessons. If the student with age $ 16 $ will refuse to study, the average age of students in this group will become $ \frac{25+37}{2}=31 $ so there won't be any assignment that allows to start lessons. In the second test case it is impossible to start lessons initially. However, if the $ 3 $ -rd student with age $ 111 $ will refuse to study, the average ages of groups will become $ \frac{4 + 5}{2}=4.5 $ and $ \frac{11+11}{2} = 11 $ correspondingly. Then it is possible to assing the first group to the first teacher and the second group to the third teacher.

Input

题意翻译

你决定开办一所新学校,并且你已经找到了 $n$ 个老师和 $m$ 组学生,其中,第 $i$ 组学生包含 $k_i$ 个学生。第 $i$ 个老师的编号为 $i$,第 $i$ 组学生中的第 $j$ 个学生的编号为 $(\sum\limits_{x=1}^{i-1} k_x)+j$。 你已经知道了每个老师和同学的年龄,其中第 $i$ 个老师的年龄为 $a_i$,第 $i$ 组学生中的第 $j$ 个学生的年龄为 $b_{i,j}$。为了能够顺利开课,你需要安排每个老师和每组学生进行组合。这样的安排必须满足如下条件: - 一组学生和**恰好一个**老师组合。 - 一个老师和**至多一组**学生组合。 - 每个组合中,所有该组学生的年龄的平均值不能够超过老师的年龄。 最近你听到有一个学生退学了,但是由于你听力不好,你并没有听清这个学生的编号。你知道有学生退学会使得该组学生的人数减 $1$,该组的年龄平均值也会因此受到影响,进而会影响到学校的顺利开课。于是,对于 $[1,\sum\limits_{i=1}^m k_i]$ 中的所有整数 $x$,你想知道如果编号为 $x$ 的学生退学,学校是否还能够顺利开课。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 1000$。 - $1\leqslant m\leqslant n\leqslant 10^5$,$\sum n\leqslant 10^5$。 - $1\leqslant a_i,b_{i,j}\leqslant 10^5$,$2\leqslant k_i\leqslant 10^5$,$\sum\limits_{i=1}^m k_i\leqslant 2\times 10^5$。 Translated by Eason_AC 2022.1.4

加入题单

上一题 下一题 算法标签: