第 1120 场 Codeforces Round(Div. 2)
D
死灭回游
Culling Game
Codeforces
未评级
原题
← C2E →

死灭回游AI (CI翻译)

Bessie is making a show called Moojutsu Cowsen. For one episode, she invites $n$ sorcerers and lines them up from left to right. The initial skill level of the $i$-th sorcerer is $a_i$.

Bessie 正在制作一档名为 Moojutsu Cowsen 的节目。在其中一期节目中,她邀请了 $n$ 名咒术师,并让他们从左到右排成一列。第 $i$ 名咒术师的初始实力为 $a_i$。AI (CI翻译)

The sorcerers compete in a king-of-the-hill tournament. The leftmost remaining sorcerer starts as the champion, and his current skill is equal to his initial skill.

咒术师们将进行一场擂台赛。最左边仍在队列中的咒术师首先成为擂主,其当前实力等于他的初始实力。AI (CI翻译)

Then, the champion faces each remaining sorcerer to his right, one by one. Suppose the current champion has skill $s$, and the next sorcerer has skill $x$.

随后,擂主依次迎战右侧其余的咒术师。假设当前擂主的实力为 $s$,下一名咒术师的实力为 $x$。AI (CI翻译)

If $s \lt x$, the champion forfeits. The next sorcerer becomes the new champion with skill $x$.

如果 $s \lt x$,擂主弃权。下一名咒术师成为新的擂主,实力为 $x$。AI (CI翻译)

Otherwise, the champion fights and wins (the champion still wins when $s = x$). In this case, the champion's current skill becomes $s+x$.

否则,擂主进行战斗并获胜(当 $s = x$ 时,擂主仍然获胜)。此时,擂主的当前实力变为 $s+x$。AI (CI翻译)

Bessie finds forfeits boring, so before running the tournament, she may remove some sorcerers from the lineup.

Bessie 觉得弃权很无聊,因此在比赛开始前,她可以从队列中移除一些咒术师。AI (CI翻译)

You are given a permutation $p_1,p_2,\ldots,p_n$ of the integers from $1$ to $n$. For each $0 \le i \le n-1$, Bessie removes sorcerers $p_1,p_2,\ldots,p_i$ from the lineup. If $i=0$, no sorcerers are removed. The relative order of all remaining sorcerers does not change.

给定一个由整数 $1$ 到 $n$ 组成的排列 $p_1,p_2,\ldots,p_n$。对于每个 $0 \le i \le n-1$,Bessie 会从队列中移除编号为 $p_1,p_2,\ldots,p_i$ 的咒术师。如果 $i=0$,则不移除任何咒术师。所有剩余咒术师的相对顺序保持不变。AI (CI翻译)

For each such $i$, determine how many forfeits happen when Bessie runs the tournament using only the remaining sorcerers.

对于每个这样的 $i$,求 Bessie 仅让剩余咒术师参加比赛时,会发生多少次弃权。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各组测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($1 \le n \le 2\cdot 10^5$).

每组测试用例的第一行包含一个整数 $n$($1 \le n \le 2\cdot 10^5$)。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$).

每组测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($1 \le a_i \le 10^9$)。AI (CI翻译)

The third line of each test case contains a permutation $p_1,p_2,\ldots,p_n$ of the integers from $1$ to $n$.

每组测试用例的第三行包含一个由整数 $1$ 到 $n$ 组成的排列 $p_1,p_2,\ldots,p_n$。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output $n$ integers.

对于每组测试用例,输出 $n$ 个整数。AI (CI翻译)

The $i$-th integer should be the number of forfeits after removing sorcerers $p_1,p_2,\ldots,p_{i-1}$.

第 $i$ 个整数应为移除编号为 $p_1,p_2,\ldots,p_{i-1}$ 的咒术师后发生的弃权次数。AI (CI翻译)

Note

说明

AI (CI翻译)

For the first test case, the answers are $2,1,0,0$.

对于第一组测试用例,答案为 $2,1,0,0$。AI (CI翻译)

Before any removals, the array is $[1,2,4,3]$. The champion with skill $1$ forfeits against skill $2$, and then the champion with skill $2$ forfeits against skill $4$. The champion with skill $4$ defeats skill $3$, so there are $2$ forfeits.

在移除任何咒术师之前,数组为 $[1,2,4,3]$。实力为 $1$ 的擂主面对实力为 $2$ 的咒术师时弃权,随后实力为 $2$ 的擂主面对实力为 $4$ 的咒术师时弃权。实力为 $4$ 的擂主击败实力为 $3$ 的咒术师,因此共发生 $2$ 次弃权。AI (CI翻译)

After removing sorcerer $1$, the remaining array is $[2,4,3]$. The champion with skill $2$ forfeits against skill $4$, and then the champion with skill $4$ defeats skill $3$, so there is $1$ forfeit.

移除编号为 $1$ 的咒术师后,剩余数组为 $[2,4,3]$。实力为 $2$ 的擂主面对实力为 $4$ 的咒术师时弃权,随后实力为 $4$ 的擂主击败实力为 $3$ 的咒术师,因此共发生 $1$ 次弃权。AI (CI翻译)

After removing sorcerers $1$ and $2$, the remaining array is $[4,3]$. The champion defeats the only remaining sorcerer, so there are $0$ forfeits. After removing sorcerers $1$, $2$, and $3$, only one sorcerer remains, so there are also $0$ forfeits.

移除编号为 $1$ 和 $2$ 的咒术师后,剩余数组为 $[4,3]$。擂主击败唯一的对手,因此共发生 $0$ 次弃权。移除编号为 $1$、$2$ 和 $3$ 的咒术师后,只剩下一名咒术师,因此也发生 $0$ 次弃权。AI (CI翻译)

For the second test case, the answers are $1,0,2,1,0$.

对于第二组测试用例,答案为 $1,0,2,1,0$。AI (CI翻译)

Before any removals, the array is $[3,1,7,2,6]$. The champion with skill $3$ defeats skill $1$ and gains one skill point, then forfeits against skill $7$. After that, the champion defeats skills $2$ and $6$, so there is $1$ forfeit.

在移除任何咒术师之前,数组为 $[3,1,7,2,6]$。实力为 $3$ 的擂主击败实力为 $1$ 的咒术师,实力增加一点,然后面对实力为 $7$ 的咒术师时弃权。之后,擂主击败实力为 $2$ 和 $6$ 的咒术师,因此共发生 $1$ 次弃权。AI (CI翻译)

After removing sorcerer $3$, whose skill is $7$, the remaining array is $[3,1,2,6]$. The champion defeats every remaining sorcerer, so there are $0$ forfeits.

移除编号为 $3$、实力为 $7$ 的咒术师后,剩余数组为 $[3,1,2,6]$。擂主击败其余所有咒术师,因此共发生 $0$ 次弃权。AI (CI翻译)

After also removing sorcerer $1$, the remaining array is $[1,2,6]$ The champion with skill $1$ forfeits against skill $2$, and then the champion with skill $2$ forfeits against skill $6$, so there are $2$ forfeits.

接着移除编号为 $1$ 的咒术师后,剩余数组为 $[1,2,6]$。实力为 $1$ 的擂主面对实力为 $2$ 的咒术师时弃权,随后实力为 $2$ 的擂主面对实力为 $6$ 的咒术师时弃权,因此共发生 $2$ 次弃权。AI (CI翻译)

After also removing sorcerer $5$, the remaining array is $[1,2]$. There is $1$ forfeit. Finally, after also removing sorcerer $2$, only one sorcerer remains, so there are $0$ forfeits.

接着移除编号为 $5$ 的咒术师后,剩余数组为 $[1,2]$,共发生 $1$ 次弃权。最后,再移除编号为 $2$ 的咒术师后,只剩下一名咒术师,因此共发生 $0$ 次弃权。AI (CI翻译)

样例

Input #1
3
4
1 2 4 3
1 2 3 4
5
3 1 7 2 6
3 1 5 2 4
6
10 1 2 20 3 4
4 1 2 3 5 6
Output #1
2 1 0 0
1 0 2 1 0
1 0 3 2 1 0
InputCopy OutputCopy
题目信息
题号
2263D
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。