CF1326E.Bombs

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a permutation, p1,p2,…,pnp_1, p_2, \ldots, p_n.

Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.

For some fixed configuration of bombs, consider the following process. Initially, there is an empty set, AA.

For each ii from 11 to nn:

  • Add pip_i to AA.
  • If the ii-th position contains a bomb, remove the largest element in AA.

After the process is completed, AA will be non-empty. The cost of the configuration of bombs equals the largest element in AA.

You are given another permutation, q1,q2,…,qnq_1, q_2, \ldots, q_n.

For each 1≤i≤n1 \leq i \leq n, find the cost of a configuration of bombs such that there exists a bomb in positions q1,q2,…,qi−1q_1, q_2, \ldots, q_{i-1}.

For example, for i=1i=1, you need to find the cost of a configuration without bombs, and for i=ni=n, you need to find the cost of a configuration with bombs in positions q1,q2,…,qn−1q_1, q_2, \ldots, q_{n-1}.

给你一个排列 p1,p2,…,pnp_1, p_2, \ldots, p_n。

设想该排列的某些位置上放置了炸弹,且至少存在一个位置没有炸弹。

对于某组固定的炸弹位置配置,考虑如下过程:初始时集合 AA 为空。

对每个 ii 从 11 到 nn 执行以下操作:

  • 将 pip_i 加入 AA;
  • 若第 ii 个位置上有炸弹,则从 AA 中移除最大元素。

该过程结束后,AA 非空。该炸弹配置的代价定义为此时 AA 中的最大元素。

你另被给定一个排列 q1,q2,…,qnq_1, q_2, \ldots, q_n。

对每个 1≤i≤n1 \leq i \leq n,求满足如下条件的炸弹配置的代价:在位置 q1,q2,…,qi−1q_1, q_2, \ldots, q_{i-1} 上均放置炸弹。

例如,当 i=1i=1 时,你需要计算无炸弹配置的代价;当 i=ni=n 时,你需要计算在位置 q1,q2,…,qn−1q_1, q_2, \ldots, q_{n-1} 上均放置炸弹的配置的代价。

输入格式

The first line contains a single integer, nn (2≤n≤300 0002 \leq n \leq 300\,000).

The second line contains nn distinct integers p1,p2,…,pnp_1, p_2, \ldots, p_n (1≤pi≤n)1 \leq p_i \leq n).

The third line contains nn distinct integers q1,q2,…,qnq_1, q_2, \ldots, q_n (1≤qi≤n)1 \leq q_i \leq n).

第一行包含一个整数 nn(2≤n≤300 0002 \leq n \leq 300\,000)。

第二行包含 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n)。

第三行包含 nn 个互不相同的整数 q1,q2,…,qnq_1, q_2, \ldots, q_n(1≤qi≤n1 \leq q_i \leq n)。

输出格式

Print nn space-separated integers, such that the ii-th of them equals the cost of a configuration of bombs in positions q1,q2,…,qi−1q_1, q_2, \ldots, q_{i-1}.

输出 nn 个以空格分隔的整数,其中第 ii 个整数等于在位置 q1,q2,…,qi−1q_1, q_2, \ldots, q_{i-1} 放置炸弹的配置的代价。

输入输出样例

  • 输入#1

    3
    3 2 1
    1 2 3

    输出#1

    3 2 1
  • 输入#2

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

    输出#2

    6 5 5 5 4 1

说明/提示

In the first test:

  • If there are no bombs, AA is equal to 1,2,3{1, 2, 3} at the end of the process, so the cost of the configuration is 33.
  • If there is one bomb in position 11, AA is equal to 1,2{1, 2} at the end of the process, so the cost of the configuration is 22;
  • If there are two bombs in positions 11 and 22, AA is equal to 1{1} at the end of the process, so the cost of the configuration is 11.

In the second test:

Let's consider the process for i=4i = 4. There are three bombs on positions q1=5q_1 = 5, q2=2q_2 = 2, and q3=1q_3 = 1.

At the beginning, A=A = {}.

  • Operation 11: Add p1=2p_1 = 2 to AA, so AA is equal to 2{2}. There exists a bomb in position 11, so we should delete the largest element from AA. AA is equal to {}.
  • Operation 22: Add p2=3p_2 = 3 to AA, so AA is equal to 3{3}. There exists a bomb in position 22, so we should delete the largest element from AA. AA is equal to {}.
  • Operation 33: Add p3=6p_3 = 6 to AA, so AA is equal to 6{6}. There is no bomb in position 33, so we do nothing.
  • Operation 44: Add p4=1p_4 = 1 to AA, so AA is equal to 1,6{1, 6}. There is no bomb in position 44, so we do nothing.
  • Operation 55: Add p5=5p_5 = 5 to AA, so AA is equal to 1,5,6{1, 5, 6}. There exists a bomb in position 55, so we delete the largest element from AA. Now, AA is equal to 1,5{1, 5}.
  • Operation 66: Add p6=4p_6 = 4 to AA, so AA is equal to 1,4,5{1, 4, 5}. There is no bomb in position 66, so we do nothing.

In the end, we have A=1,4,5A = {1, 4, 5}, so the cost of the configuration is equal to 55.

在第一个测试中:

  • 如果没有炸弹,过程结束时 A={1,2,3}A = \{1, 2, 3\},因此该配置的代价为 33;
  • 如果在位置 11 处有一颗炸弹,过程结束时 A={1,2}A = \{1, 2\},因此该配置的代价为 22;
  • 如果在位置 11 和 22 处各有一颗炸弹,过程结束时 A={1}A = \{1\},因此该配置的代价为 11。

在第二个测试中:

考虑 i=4i = 4 时的过程。炸弹位于位置 q1=5q_1 = 5、q2=2q_2 = 2 和 q3=1q_3 = 1。

初始时,A={}A = \{\}。

  • 操作 11:将 p1=2p_1 = 2 加入 AA,此时 A={2}A = \{2\}。位置 11 处存在一颗炸弹,因此需从 AA 中删除最大元素,A={}A = \{\};
  • 操作 22:将 p2=3p_2 = 3 加入 AA,此时 A={3}A = \{3\}。位置 22 处存在一颗炸弹,因此需从 AA 中删除最大元素,A={}A = \{\};
  • 操作 33:将 p3=6p_3 = 6 加入 AA,此时 A={6}A = \{6\}。位置 33 处没有炸弹,因此不执行任何操作;
  • 操作 44:将 p4=1p_4 = 1 加入 AA,此时 A={1,6}A = \{1, 6\}。位置 44 处没有炸弹,因此不执行任何操作;
  • 操作 55:将 p5=5p_5 = 5 加入 AA,此时 A={1,5,6}A = \{1, 5, 6\}。位置 55 处存在一颗炸弹,因此需从 AA 中删除最大元素,此时 A={1,5}A = \{1, 5\};
  • 操作 66:将 p6=4p_6 = 4 加入 AA,此时 A={1,4,5}A = \{1, 4, 5\}。位置 66 处没有炸弹,因此不执行任何操作。

最终,A={1,4,5}A = \{1, 4, 5\},因此该配置的代价为 55。

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

首页