CF2262B.Culling Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

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.

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

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

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

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

You are given a permutation p1,p2,…,pnp_1,p_2,\ldots,p_n of the integers from 11 to nn. For each 0≤i≤n−10 \le i \le n-1, Bessie removes sorcerers p1,p2,…,pip_1,p_2,\ldots,p_i from the lineup. If i=0i=0, no sorcerers are removed. The relative order of all remaining sorcerers does not change.

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

贝茜正在制作一档名为《哞术牛生》的节目。在其中一集里,她邀请了 nn 位法师,并将他们从左到右排成一列。第 ii 位法师的初始技能值为 aia_i。

这些法师将进行一场“山顶之王”式淘汰赛。剩余法师中最左侧的一位首先成为冠军,其当前技能值等于其初始技能值。

随后,冠军依次挑战其右侧所有尚未被淘汰的法师。假设当前冠军的技能值为 ss,下一位法师的技能值为 xx:

  • 若 s<xs \lt x,则冠军弃权;下一位法师成为新冠军,其技能值为 xx;
  • 否则(即 s≥xs \ge x),冠军出战并获胜(当 s=xs = x 时也视为获胜);此时冠军的当前技能值更新为 s+xs+x。

贝茜觉得弃权环节很无趣,因此在正式举办比赛前,她可以预先从队列中移除若干法师。

你将获得一个 11 到 nn 的排列 p1,p2,…,pnp_1,p_2,\ldots,p_n。对每个 0≤i≤n−10 \le i \le n-1,贝茜会从队列中移除编号为 p1,p2,…,pip_1,p_2,\ldots,p_i 的法师(若 i=0i=0,则不移除任何法师)。所有未被移除的法师保持原有相对顺序。

对每个这样的 ii,请计算:仅使用剩余法师运行上述比赛时,总共会发生多少次弃权。

输入格式

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

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

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091 \le a_i \le 10^9).

The third line of each test case contains a permutation p1,p2,…,pnp_1,p_2,\ldots,p_n of the integers from 11 to nn.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091 \le a_i \le 10^9)。

每个测试用例的第三行包含一个 11 到 nn 的排列 p1,p2,…,pnp_1,p_2,\ldots,p_n。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers.

The ii-th integer should be the number of forfeits after removing sorcerers p1,p2,…,pi−1p_1,p_2,\ldots,p_{i-1}.

对于每个测试用例,输出 nn 个整数。

第 ii 个整数应为移除巫师 p1,p2,…,pi−1p_1, p_2, \ldots, p_{i-1} 后的弃权次数。

输入输出样例

  • 输入#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

    输出#1

    2 1 0 0 
    1 0 2 1 0 
    1 0 3 2 1 0

说明/提示

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

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

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

After removing sorcerers 11 and 22, the remaining array is [4,3][4,3]. The champion defeats the only remaining sorcerer, so there are 00 forfeits. After removing sorcerers 11, 22, and 33, only one sorcerer remains, so there are also 00 forfeits.

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

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

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

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

After also removing sorcerer 55, the remaining array is [1,2][1,2]. There is 11 forfeit. Finally, after also removing sorcerer 22, only one sorcerer remains, so there are 00 forfeits.

对于第一个测试用例,答案为 2,1,0,02,1,0,0。

在任何移除操作之前,数组为 [1,2,4,3][1,2,4,3]。技能值为 11 的冠军输给技能值为 22 的冠军,随后技能值为 22 的冠军又输给技能值为 44 的冠军。技能值为 44 的冠军击败技能值为 33 的冠军,因此共发生 22 次弃权(forfeit)。

移除第 11 位术士后,剩余数组为 [2,4,3][2,4,3]。技能值为 22 的冠军输给技能值为 44 的冠军,随后技能值为 44 的冠军击败技能值为 33 的冠军,因此共发生 11 次弃权。

再移除第 11 和第 22 位术士后,剩余数组为 [4,3][4,3]。冠军击败唯一剩下的术士,因此共发生 00 次弃权。再移除第 11、第 22 和第 33 位术士后,仅剩一位术士,因此也发生 00 次弃权。

对于第二个测试用例,答案为 1,0,2,1,01,0,2,1,0。

在任何移除操作之前,数组为 [3,1,7,2,6][3,1,7,2,6]。技能值为 33 的冠军击败技能值为 11 的冠军并获得 11 点技能值,随后输给技能值为 77 的冠军。之后,该冠军(此时技能值为 44)击败技能值为 22 和 66 的冠军,因此共发生 11 次弃权。

移除技能值为 77 的第 33 位术士后,剩余数组为 [3,1,2,6][3,1,2,6]。冠军击败所有剩余术士,因此共发生 00 次弃权。

再移除第 11 位术士后,剩余数组为 [1,2,6][1,2,6]。技能值为 11 的冠军输给技能值为 22 的冠军,随后技能值为 22 的冠军又输给技能值为 66 的冠军,因此共发生 22 次弃权。

再移除第 55 位术士后,剩余数组为 [1,2][1,2],共发生 11 次弃权。最后,再移除第 22 位术士后,仅剩一位术士,因此共发生 00 次弃权。

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

首页