CF1253B.Silly Mistake

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Central Company has an office with a sophisticated security system. There are 10610^6 employees, numbered from 11 to 10610^6.

The security system logs entrances and departures. The entrance of the ii-th employee is denoted by the integer ii, while the departure of the ii-th employee is denoted by the integer −i-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][1, 7, -7, 3, -1, -3] is a valid day (11 enters, 77 enters, 77 leaves, 33 enters, 11 leaves, 33 leaves).
  • [2,−2,3,−3][2, -2, 3, -3] is also a valid day.
  • [2,5,−5,5,−5,−2][2, 5, -5, 5, -5, -2] is not a valid day, because 55 entered the office twice during the same day.
  • [−4,4][-4, 4] is not a valid day, because 44 left the office without being in it.
  • [4][4] is not a valid day, because 44 entered the office and didn't leave it before the end of the day.

There are nn events a1,a2,…,ana_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 aa 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=8n=8 and a=[1,−1,1,2,−1,−2,3,−3]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 ∣ 1,2,−1,−2,3,−3]a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3].

Help the administrator to partition the given array aa 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.

中央公司拥有一套精密的安全系统。公司共有 10610^6 名员工,编号从 11 到 10610^6。

该安全系统会记录员工的进出事件。第 ii 名员工的进入事件用整数 ii 表示,其离开事件用整数 −i-i 表示。

公司对办公室访问有若干严格规定:

  • 每名员工每天最多只能进入办公室一次;
  • 员工显然不能在当天尚未进入办公室的前提下离开办公室;
  • 每天开始时和结束时,办公室内均为空(员工不得留宿过夜);办公室在一天中的任意时刻也可能为空。

满足上述所有条件的事件数组称为有效的一天(valid day)。

以下是一些有效或无效“一天”的示例:

  • [1,7,−7,3,−1,−3][1, 7, -7, 3, -1, -3] 是有效的一天(11 进入,77 进入,77 离开,33 进入,11 离开,33 离开);
  • [2,−2,3,−3][2, -2, 3, -3] 也是有效的一天;
  • [2,5,−5,5,−5,−2][2, 5, -5, 5, -5, -2] 不是有效的一天,因为 55 在同一天内进入了两次;
  • [−4,4][-4, 4] 不是有效的一天,因为 44 在未进入办公室的情况下就离开了;
  • [4][4] 不是有效的一天,因为 44 进入了办公室,但在当天结束前未离开。

现给定按发生顺序排列的 nn 个事件:a1,a2,…,ana_1, a_2, \ldots, a_n。该数组对应一个或多个连续的天数。系统管理员不慎擦除了每个事件所对应的日期,但未改变事件的先后顺序。

你需要将事件数组 aa 划分为若干连续的子数组,使得每个子数组都表示一个非空的有效的一天(若不可能则需报告)。每个数组元素必须且仅属于划分中的某一个连续子数组;每个子数组本身必须是一个有效的一天。

例如,若 n=8n = 8 且 a=[1,−1,1,2,−1,−2,3,−3]a = [1, -1, 1, 2, -1, -2, 3, -3],则可将其划分为两个连续子数组,各自构成有效的一天:

a=[1,−1 ∣ 1,2,−1,−2,3,−3]a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3]

请帮助管理员完成该数组的所需划分,或判定其不可能实现。只需找出任意一种满足要求的划分即可,无需最小化或最大化划分段数。

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−106≤ai≤106-10^6 \le a_i \le 10^6 and ai≠0a_i \neq 0).

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−106≤ai≤106-10^6 \le a_i \le 10^6,且 ai≠0a_i \neq 0)。

输出格式

If there is no valid partition, print −1-1. Otherwise, print any valid partition in the following format:

  • On the first line print the number dd of days (1≤d≤n1 \le d \le n).
  • On the second line, print dd integers c1,c2,…,cdc_1, c_2, \ldots, c_d (1≤ci≤n1 \le c_i \le n and c1+c2+…+cd=nc_1 + c_2 + \ldots + c_d = n), where cic_i is the number of events in the ii-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-1。否则,按以下格式输出任意一种有效的划分方案:

  • 第一行输出天数 dd(1≤d≤n1 \le d \le n);
  • 第二行输出 dd 个整数 c1,c2,…,cdc_1, c_2, \ldots, c_d(满足 1≤ci≤n1 \le c_i \le n 且 c1+c2+…+cd=nc_1 + c_2 + \ldots + c_d = n),其中 cic_i 表示第 ii 天的事件数量。

若存在多种有效解,可输出其中任意一种。你无需最小化或最大化天数。

输入输出样例

  • 输入#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][1, -1] and [1,2,−1,−2,3,−3][1, 2, -1, -2, 3, -3] (d=2d = 2 and c=[2,6]c = [2, 6]). The only other valid solution would be to split the array into [1,−1][1, -1], [1,2,−1,−2][1, 2, -1, -2] and [3,−3][3, -3] (d=3d = 3 and c=[2,4,2]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.

在第一个例子中,整个数组构成一个有效的“天”。

在第二个例子中,一种可能的有效解法是将数组分割为 [1,−1][1, -1] 和 [1,2,−1,−2,3,−3][1, 2, -1, -2, 3, -3](此时 d=2d = 2,且 c=[2,6]c = [2, 6])。另一种唯一有效的解法是将数组分割为 [1,−1][1, -1]、[1,2,−1,−2][1, 2, -1, -2] 和 [3,−3][3, -3](此时 d=3d = 3,且 c=[2,4,2]c = [2, 4, 2])。两种解法均被接受。

在第三和第四个例子中,我们可以证明不存在有效解。请注意,输入中给出的数组并不保证表示一组逻辑自洽的事件。

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

首页