CF925E.May Holidays

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It's May in Flatland, and there are mm days in this month. Despite the fact that May Holidays are canceled long time ago, employees of some software company still have a habit of taking short or long vacations in May.

Of course, not all managers of the company like this. There are nn employees in the company that form a tree-like structure of subordination: each employee has a unique integer id ii between 11 and nn, and each employee with id ii (except the head manager whose id is 1) has exactly one direct manager with id pip_i. The structure of subordination is not cyclic, i.e. if we start moving from any employee to his direct manager, then we will eventually reach the head manager. We define that an employee uu is a subordinate of an employee vv, if vv is a direct manager of uu, or the direct manager of uu is a subordinate of vv. Let sis_i be the number of subordinates the ii-th employee has (for example, s1=n−1s_1 = n - 1, because all employees except himself are subordinates of the head manager).

Each employee ii has a bearing limit of tit_i, which is an integer between 00 and sis_i. It denotes the maximum number of the subordinates of the ii-th employee being on vacation at the same moment that he can bear. If at some moment strictly more than tit_i subordinates of the ii-th employee are on vacation, and the ii-th employee himself is not on a vacation, he becomes displeased.

In each of the mm days of May exactly one event of the following two types happens: either one employee leaves on a vacation at the beginning of the day, or one employee returns from a vacation in the beginning of the day. You know the sequence of events in the following mm days. Your task is to compute for each of the mm days the number of displeased employees on that day.

现在是平面上的五月,这个月共有 mm 天。尽管五月假期早已被取消,某软件公司的员工仍习惯在五月休短假或长假。

当然,并非公司所有经理都喜欢这样。公司共有 nn 名员工,他们构成一棵树状的上下级关系结构:每名员工拥有一个唯一的整数编号 ii(取值范围为 11 到 nn);除总负责人(编号为 11)外,其余每名编号为 ii 的员工恰好有一名直属上级,其编号为 pip_i。该上下级结构无环,即从任意员工出发,沿其直属上级不断向上追溯,最终必能到达总负责人。我们定义:若员工 vv 是员工 uu 的直属上级,或员工 uu 的直属上级是 vv 的下属,则称员工 uu 是员工 vv 的下属。令 sis_i 表示第 ii 号员工所拥有的下属人数(例如,s1=n−1s_1 = n - 1,因为除其本人外的所有员工均为总负责人的下属)。

每名员工 ii 都有一个承受上限 tit_i,它是一个介于 00 和 sis_i 之间的整数,表示第 ii 号员工在同一时刻所能容忍的、正在休假的下属人数的最大值。若在某一时刻,第 ii 号员工的正在休假的下属人数严格超过 tit_i,且第 ii 号员工本人并未休假,则他将感到不满。

在五月的 mm 天中,每天恰好发生以下两类事件之一:要么一名员工于当天开始时开始休假,要么一名员工于当天开始时结束休假。你已知接下来 mm 天内事件发生的序列。你的任务是:对这 mm 天中的每一天,计算当天感到不满的员工人数。

输入格式

The first line contains two integers nn and mm (2≤n,m≤1052 \leq n, m \leq 10^5) — the number of employees in the company and the number of days in May.

The second line contains n−1n - 1 integers p2,p3,…,pnp_2, p_3, \ldots, p_n (1≤pi≤n1 \leq p_i \leq n), denoting the direct managers of employees.

The third line contains nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n (0≤ti≤si0 \leq t_i \leq s_i), denoting the bearing limits of empoyees.

The fourth line contains mm integers q1,q2,…,qmq_1, q_2, \ldots, q_m (1≤∣qi∣≤n1 \leq |q_i| \leq n, qi≠0q_i \ne 0), denoting the events. If qiq_i is positive, then the employee with id qiq_i leaves for a vacation starting from this day, if qiq_i is negative, then the employee −qi-q_i returns from a vacation starting from this day. In the beginning of May no employee is on vacation. It is guaranteed that if some employee leaves for a vacation, he is not on a vacation at the moment and vice versa.

第一行包含两个整数 nn 和 mm(2≤n,m≤1052 \leq n, m \leq 10^5)—— 分别表示公司员工人数和五月份的天数。

第二行包含 n−1n - 1 个整数 p2,p3,…,pnp_2, p_3, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n),表示员工 2,3,…,n2, 3, \ldots, n 的直属上级。

第三行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \ldots, t_n(0≤ti≤si0 \leq t_i \leq s_i),表示各员工的承压上限。

第四行包含 mm 个整数 q1,q2,…,qmq_1, q_2, \ldots, q_m(1≤∣qi∣≤n1 \leq |q_i| \leq n,qi≠0q_i \ne 0),表示每天发生的事件。若 qiq_i 为正数,则编号为 qiq_i 的员工从当天起开始休假;若 qiq_i 为负数,则编号为 −qi-q_i 的员工从当天起结束休假并返岗。五月初时,没有任何员工在休假。保证:若某员工开始休假,则其当前一定不在休假状态;反之亦然。

输出格式

Print a sequence of mm integers a1,a2,…,ama_1, a_2, \ldots, a_m, where aia_i is the number of displeased employees on the ii-th day.

输出一个包含 mm 个整数的序列 a1,a2,…,ama_1, a_2, \ldots, a_m,其中 aia_i 表示第 ii 天不满意的员工人数。

输入输出样例

  • 输入#1

    7 8
    4 5 1 1 5 5
    0 0 0 1 2 0 0
    2 6 3 7 -2 4 -3 1

    输出#1

    1 1 1 2 2 2 1 0
  • 输入#2

    5 6
    1 2 3 4
    4 0 0 1 0
    1 5 2 3 -5 -1

    输出#2

    0 2 1 0 0 0

说明/提示

In the first sample test after employee with id 2 leaves for a vacation at the first day, the head manager with id 1 becomes displeased as he does not want any of his subordinates to go for a vacation. At the fourth day employee with id 5 becomes displeased as his last remaining employee with id 7 leaves for a vacation. At the fifth day employee with id 2 returns from the vacation, but it does not affect the number of displeased employees as the employees 5 and 1 are still displeased. At the sixth day employee with id 3 returns back from the vacation, preventing the employee with id 5 from being displeased and at the last day the head manager with id 1 leaves for a vacation, leaving the company without the displeased people at all.

在第一个样例测试中,编号为 2 的员工在第一天开始休假后,作为主管的编号为 1 的员工变得不满,因为他不希望自己的任何下属去休假。第四天,编号为 5 的员工变得不满,因为其最后一名下属(编号为 7 的员工)也去休假了。第五天,编号为 2 的员工结束休假返回岗位,但这并未改变不满员工的数量,因为编号为 5 和 1 的员工仍处于不满状态。第六天,编号为 3 的员工结束休假返回岗位,从而阻止了编号为 5 的员工继续不满;而在最后一天,编号为 1 的主管开始休假,公司中不再有任何不满的员工。

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

首页