CF2231D.Maximum Prefix Sums

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

521 sounds the same as "I love you" in Chinese. On this special day, Little S wants to give Little A some well-prepared sequences to recall their friendship sealed for years.

Little S has prepared an array a1,a2,…,ana_1, a_2, \ldots, a_n. Let's define its prefix sums array b1,b2,…,bnb_1, b_2, \ldots, b_n, where bi=a1+a2+…+aib_i = a_1 + a_2 + \ldots + a_i. Also define the prefix maximum array of bb: c1,c2,…,cnc_1, c_2, \ldots, c_n, where ci=max⁡(b1,b2,…,bi)c_i = \max(b_1, b_2, \ldots, b_i).

Now array aa has been partially lost, but luckily Little S still keeps the array cc. Your task is to restore the array aa and send it to Little A, or report that no such array exists — in this case, the kind and cute Little A won't get mad either.

Formally, you are given a binary string ss, a partially filled array aa, and an array cc, where:

  • If you remember the value of aia_i, then si=1s_i = 1, and you are given the true value of aia_i.
  • If you do not remember the value of aia_i, then si=0s_i = 0, and you are given ai=0a_i = 0.

521 在中文中与 “I love you” 谐音。在这个特别的日子里,小 S 想要送给小 A 一些精心准备的数列,以唤起他们多年以来牢不可破的友谊。

小 S 已准备好一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n。我们定义其前缀和数组为 b1,b2,…,bnb_1, b_2, \ldots, b_n,其中 bi=a1+a2+…+aib_i = a_1 + a_2 + \ldots + a_i;再定义 bb 的前缀最大值数组 c1,c2,…,cnc_1, c_2, \ldots, c_n,其中 ci=max⁡(b1,b2,…,bi)c_i = \max(b_1, b_2, \ldots, b_i)。

目前数组 aa 已部分丢失,但幸运的是,小 S 仍保留着数组 cc。你的任务是根据 cc 恢复出原数组 aa 并将其发送给小 A;若不存在满足条件的数组,则报告无解——此时善良又可爱的小 A 也不会生气哦。

形式化地,你将获得一个二进制字符串 ss、一个部分填充的数组 aa 以及一个数组 cc,满足:

  • 若你记得 aia_i 的值,则 si=1s_i = 1,且你被给出真实的 aia_i 值;
  • 若你不记得 aia_i 的值,则 si=0s_i = 0,且你被给出 ai=0a_i = 0。

输入格式

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 an integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains a binary string ss (si∈0,1s_i \in {\texttt{0}, \texttt{1}}) of length nn.

The third line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (∣ai∣≤106|a_i| \le 10^6). If si=0s_i = \texttt{0}, then it is guaranteed that ai=0a_i = 0.

The fourth line of each test case contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (∣ci∣≤2⋅1011|c_i| \le 2 \cdot 10^{11}).

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 的二进制字符串 ss(其中 si∈{0,1}s_i \in \{\texttt{0}, \texttt{1}\})。

每个测试用例的第三行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(∣ai∣≤106|a_i| \le 10^6)。若 si=0s_i = \texttt{0},则保证 ai=0a_i = 0。

每个测试用例的第四行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(∣ci∣≤2⋅1011|c_i| \le 2 \cdot 10^{11})。

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

输出格式

For each test case, print "Yes" in the first line if the array aa exists, otherwise print "No". You may print the answer in any case. For example, "YeS", "YES", "NO", "nO" will also be accepted.

If there is at least one solution, print nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (∣ai∣≤1018|a_i| \leq 10^{18}) in the second line. If there are multiple suitable arrays, you may print any of them.

对于每个测试用例,如果数组 aa 存在,则在第一行输出 "Yes";否则输出 "No"。你可以以任意大小写形式输出答案,例如 "YeS"、"YES"、"NO"、"nO" 均可接受。

如果至少存在一个解,则在第二行输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(满足 ∣ai∣≤1018|a_i| \leq 10^{18})。如果存在多个合适的数组,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    10
    4
    1110
    1 2 -1 0
    1 3 3 3
    5
    00001
    0 0 0 0 5
    -4 -4 -1 -1 -1
    1
    1
    0
    1
    6
    001111
    0 0 2 -3 3 -6
    -5 -2 0 0 0 0
    5
    11110
    1 2 0 5 0
    1 2 2 7 6
    2
    01
    0 1
    -1 -1
    6
    001010
    0 0 5 0 3 0
    3 3 4 9 13 16
    6
    000100
    0 0 0 4 0 0
    2 6 6 7 7 7
    2
    00
    0 0
    4 -1
    8
    11111111
    6 1 1 2 0 5 1 9
    6 7 8 10 10 15 16 25

    输出#1

    Yes
    1 2 -1 0
    Yes
    -4 0 3 -6 5
    No
    Yes
    -5 3 2 -3 3 -6
    No
    No
    No
    Yes
    2 4 -3 4 -100 0
    No
    Yes
    6 1 1 2 0 5 1 9

说明/提示

In the first test case, we have:

  • a=[1,2,−1,0]a = [1, 2, -1, 0].
  • b=[1,3,2,2]b = [1, 3, 2, 2].
  • c=[1,3,3,3]c = [1, 3, 3, 3].

In the third test case, the correct array aa should be equal to [1][1], so no solution exists.

在第一个测试用例中,我们有:

  • a=[1,2,−1,0]a = [1, 2, -1, 0]。
  • b=[1,3,2,2]b = [1, 3, 2, 2]。
  • c=[1,3,3,3]c = [1, 3, 3, 3]。

在第三个测试用例中,正确的数组 aa 应等于 [1][1],因此不存在解。

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

首页