306803: CF1253B. Silly Mistake

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

Description

Silly Mistake

题意翻译

中央公司有一个具备复杂安保系统的办公室,办公室里总共工作着 $10^6$ 个员工,从 $1$ 到 $10^6$ 编号。 一个员工的一次进入或一次离开称为一个事件。安保系统会记录员工的进出。第 $i$ 号员工的进入用正整数 $i$ 表示,他的离开用 $-i$ 表示。 这个公司有一些严格的规则: - 每个员工每天最多进入办公室一次。 - 每个员工不能在进入办公室前离开办公室。 - 在每天的开始和结束时,办公室都是没有人的(员工晚上不能待在办公室)。在一天的任意时刻,办公室可以是空的。 一个表示进入和离开的序列如果满足上述规则,就被称为一个有效日。 现在,有 $n$ 个按照发生的先后顺序排列的事件 $a_1, a_2,......,a_n$。这个序列对应着一天或多天。由于不可抗力,安保系统的管理员清除了每个事件发生的日期,但没有改变事件发生的顺序。 你需要将这个序列 $a$ 划分成一些连续的子串,其中每一个子串代表一个非空有效日(或者说明不存在符合条件的划分)。序列中的每个元素都应当被划分到一个子串中,划分出的每个子串都必须是一个有效日。 请你帮助管理员将这个序列划分成满足要求的子串,或者指出不存在符合条件的划分。找到任意一个合法划分即可,不需要最大化或最小化划分出的子串数量。

题目描述

The Central Company has an office with a sophisticated security system. There are $ 10^6 $ employees, numbered from $ 1 $ to $ 10^6 $ . The security system logs entrances and departures. The entrance of the $ i $ -th employee is denoted by the integer $ i $ , while the departure of the $ i $ -th employee is denoted by the integer $ -i $ . The company has some strict rules about access to its office: - An employee can enter the office at most once per day. - He obviously can't leave the office if he didn't enter it earlier that day. - In the beginning and at the end of every day, the office is empty (employees can't stay at night). It may also be empty at any moment of the day. Any array of events satisfying these conditions is called a valid day. Some examples of valid or invalid days: - $ [1, 7, -7, 3, -1, -3] $ is a valid day ( $ 1 $ enters, $ 7 $ enters, $ 7 $ leaves, $ 3 $ enters, $ 1 $ leaves, $ 3 $ leaves). - $ [2, -2, 3, -3] $ is also a valid day. - $ [2, 5, -5, 5, -5, -2] $ is not a valid day, because $ 5 $ entered the office twice during the same day. - $ [-4, 4] $ is not a valid day, because $ 4 $ left the office without being in it. - $ [4] $ is not a valid day, because $ 4 $ entered the office and didn't leave it before the end of the day. There are $ n $ events $ a_1, a_2, \ldots, a_n $ , in the order they occurred. This array corresponds to one or more consecutive days. The system administrator erased the dates of events by mistake, but he didn't change the order of the events. You must partition (to cut) the array $ a $ of events into contiguous subarrays, which must represent non-empty valid days (or say that it's impossible). Each array element should belong to exactly one contiguous subarray of a partition. Each contiguous subarray of a partition should be a valid day. For example, if $ n=8 $ and $ a=[1, -1, 1, 2, -1, -2, 3, -3] $ then he can partition it into two contiguous subarrays which are valid days: $ a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3] $ . Help the administrator to partition the given array $ a $ in the required way or report that it is impossible to do. Find any required partition, you should not minimize or maximize the number of parts.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ). The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ -10^6 \le a_i \le 10^6 $ and $ a_i \neq 0 $ ).

输出格式


If there is no valid partition, print $ -1 $ . Otherwise, print any valid partition in the following format: - On the first line print the number $ d $ of days ( $ 1 \le d \le n $ ). - On the second line, print $ d $ integers $ c_1, c_2, \ldots, c_d $ ( $ 1 \le c_i \le n $ and $ c_1 + c_2 + \ldots + c_d = n $ ), where $ c_i $ is the number of events in the $ i $ -th day. If there are many valid solutions, you can print any of them. You don't have to minimize nor maximize the number of days.

输入输出样例

输入样例 #1

6
1 7 -7 3 -1 -3

输出样例 #1

1
6

输入样例 #2

8
1 -1 1 2 -1 -2 3 -3

输出样例 #2

2
2 6

输入样例 #3

6
2 5 -5 5 -5 -2

输出样例 #3

-1

输入样例 #4

3
-8 1 1

输出样例 #4

-1

说明

In the first example, the whole array is a valid day. In the second example, one possible valid solution is to split the array into $ [1, -1] $ and $ [1, 2, -1, -2, 3, -3] $ ( $ d = 2 $ and $ c = [2, 6] $ ). The only other valid solution would be to split the array into $ [1, -1] $ , $ [1, 2, -1, -2] $ and $ [3, -3] $ ( $ d = 3 $ and $ c = [2, 4, 2] $ ). Both solutions are accepted. In the third and fourth examples, we can prove that there exists no valid solution. Please note that the array given in input is not guaranteed to represent a coherent set of events.

Input

题意翻译

中央公司有一个具备复杂安保系统的办公室,办公室里总共工作着 $10^6$ 个员工,从 $1$ 到 $10^6$ 编号。 一个员工的一次进入或一次离开称为一个事件。安保系统会记录员工的进出。第 $i$ 号员工的进入用正整数 $i$ 表示,他的离开用 $-i$ 表示。 这个公司有一些严格的规则: - 每个员工每天最多进入办公室一次。 - 每个员工不能在进入办公室前离开办公室。 - 在每天的开始和结束时,办公室都是没有人的(员工晚上不能待在办公室)。在一天的任意时刻,办公室可以是空的。 一个表示进入和离开的序列如果满足上述规则,就被称为一个有效日。 现在,有 $n$ 个按照发生的先后顺序排列的事件 $a_1, a_2,......,a_n$。这个序列对应着一天或多天。由于不可抗力,安保系统的管理员清除了每个事件发生的日期,但没有改变事件发生的顺序。 你需要将这个序列 $a$ 划分成一些连续的子串,其中每一个子串代表一个非空有效日(或者说明不存在符合条件的划分)。序列中的每个元素都应当被划分到一个子串中,划分出的每个子串都必须是一个有效日。 请你帮助管理员将这个序列划分成满足要求的子串,或者指出不存在符合条件的划分。找到任意一个合法划分即可,不需要最大化或最小化划分出的子串数量。

加入题单

算法标签: