AT_ndpc2026_f.Set

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a permutation P=(P1,P2,…,PN)P = (P_1, P_2, \dots, P_N) of (1,2,…,N)(1, 2, \dots, N) and an integer array A1,A2,…,ANA_1, A_2, \dots, A_N of length NN.

A subset SS of the set {1,2,…,N}\lbrace 1,2,\dots,N \rbrace is called a good set if it satisfies the following condition:

  • For every pair of integers (x,y)(x, y) such that x<yx < y and x,y∈Sx, y \in S, the following holds:
    • Let zz be the integer such that Pz=min⁡(Px,Px+1,…,Py)P_z = \min(P_x, P_{x+1}, \dots, P_y). (Such a zz is uniquely determined.) Then, it must hold that z∈Sz \in S.

The cost of a good set SS is defined as ∑i∈SAi\displaystyle \sum_{i \in S} A_i.

For each K=1,2,…,NK = 1, 2, \dots, N, find the minimum possible cost among all good sets of size KK.

You are given TT test cases. Solve each of them.

给你一个 (1,2,…,N)(1, 2, \dots, N) 的排列 P=(P1,P2,…,PN)P = (P_1, P_2, \dots, P_N) 和一个长度为 NN 的整数数组 A1,A2,…,ANA_1, A_2, \dots, A_N。

集合 {1,2,…,N}\lbrace 1,2,\dots,N \rbrace 的子集 SS 被称为好集合,当且仅当它满足以下条件:

  • 对于任意满足 x<yx < y 且 x,y∈Sx, y \in S 的整数对 (x,y)(x, y),以下成立:
    • 设 zz 是满足 Pz=min⁡(Px,Px+1,…,Py)P_z = \min(P_x, P_{x+1}, \dots, P_y) 的整数。(这样的 zz 是唯一确定的。)则必须有 z∈Sz \in S。

好集合 SS 的代价定义为 ∑i∈SAi\displaystyle \sum_{i \in S} A_i。

对每个 K=1,2,…,NK = 1, 2, \dots, N,求所有大小为 KK 的好集合中可能的最小代价。

你将得到 TT 组测试数据。请分别求解每组数据。

输入格式

The input is given from standard input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN
P1P_1 P2P_2 …\dots PNP_N
A1A_1 A2A_2 …\dots ANA_N

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN
P1P_1 P2P_2 …\dots PNP_N
A1A_1 A2A_2 …\dots ANA_N

输出格式

Print TT lines. For the ii-th line, output the answer for the ii-th test case.
For each test case, output the answers for K=1,2,…,NK = 1,2,\dots,N in one line, separated by spaces.

输出 TT 行。对于第 ii 行,输出第 ii 个测试用例的答案。
对于每个测试用例,在一行内输出 K=1,2,…,NK = 1,2,\dots,N 对应的答案,各答案之间用空格分隔。

输入输出样例

  • 输入#1

    3
    4
    4 1 2 3
    1 8 2 4
    6
    5 3 2 4 6 1
    73 38 30 85 27 45
    10
    4 10 3 7 2 6 8 9 5 1
    853822501 687675302 281611653 844033520 423210108 339630584 780395612 207907746 285523486 359061085

    输出#1

    1 6 11 15
    27 57 95 140 213 298
    207907746 493431232 833061816 1192122901 1537883577 1896944662 2584619964 3365015576 4209049096 5062871597

说明/提示

Sample 1 Explanation:
In the first test case:

  • For K=1K=1, S={1}S=\lbrace 1 \rbrace is optimal,
  • For K=2K=2, S={3,4}S=\lbrace 3,4 \rbrace is optimal,
  • For K=3K=3, S={1,2,3}S=\lbrace 1,2,3 \rbrace is optimal,
  • For K=4K=4, S={1,2,3,4}S=\lbrace 1,2,3,4 \rbrace is optimal.

Constraints

  • 1≤T≤50001 \leq T \leq 5000
  • 1≤N≤50001 \leq N \leq 5000
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • (P1,P2,…,PN)(P_1, P_2, \dots, P_N) is a permutation of (1,2,…,N)(1,2,\dots,N)
  • The sum of NN over all test cases is at most 50005000
  • All input values are integers

样例 1 解释:
在第一个测试用例中:

  • 当 K=1K=1 时,最优集合为 S={1}S=\lbrace 1 \rbrace;
  • 当 K=2K=2 时,最优集合为 S={3,4}S=\lbrace 3,4 \rbrace;
  • 当 K=3K=3 时,最优集合为 S={1,2,3}S=\lbrace 1,2,3 \rbrace;
  • 当 K=4K=4 时,最优集合为 S={1,2,3,4}S=\lbrace 1,2,3,4 \rbrace。

约束条件

  • 1≤T≤50001 \leq T \leq 5000
  • 1≤N≤50001 \leq N \leq 5000
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • (P1,P2,…,PN)(P_1, P_2, \dots, P_N) 是 (1,2,…,N)(1,2,\dots,N) 的一个排列;
  • 所有测试用例的 NN 之和不超过 50005000;
  • 所有输入值均为整数。

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

首页