#P95. [NOI 2025 Day 1] 序列变换

[NOI 2025 Day 1] 序列变换

Person in Charge

Problem Description

Given two integer sequences B=[b1,,bn]B = [b_1, \ldots, b_n] and C=[c1,,cn]C = [c_1, \ldots, c_n], each of length nn. For a non-negative integer sequence D=[d1,,dn]D = [d_1, \ldots, d_n] of length nn, let S(D)S(D) be the set of indices ii where di=0d_i = 0. Define f(D)=iS(D)bif(D) = \sum_{i \in S(D)} b_i and g(D)=iS(D)cig(D) = \prod_{i \in S(D)} c_i. Specifically, if S(D)S(D) is empty, then f(D)=0f(D) = 0 and g(D)=1g(D) = 1.

Little L has a positive integer sequence A=[a1,,an]A = [a_1, \ldots, a_n] of length nn. Little L can perform the following modifications on the sequence AA:

  • Choose two adjacent indices i,ji, j in AA (i.e., 1i,jn1 \le i, j \le n and ij=1|i - j| = 1). If aiaja_i \le a_j, then set aja_j to ajaia_j - a_i and set aia_i to 00.

Little L can perform any number of such modifications or none at all. For all sequences DD that can be obtained from AA through these modifications, Little L wants to find the maximum value of f(D)f(D) and the sum of g(D)g(D). Formally, let T(A)T(A) be the set of all sequences obtainable from AA through the above operations. You need to compute maxDT(A)f(D)\max_{D \in T(A)} f(D) and DT(A)g(D)\sum_{D \in T(A)} g(D). Since DT(A)g(D)\sum_{D \in T(A)} g(D) may be large, you only need to output its value modulo 1,000,000,0071,000,000,007.

Scoring

For each test case:

  • Correctly answering maxDT(A)f(D)\max_{D \in T(A)} f(D) for all test data will earn 40%40\% of the points for that test case.
  • Correctly answering DT(A)g(D)\sum_{D \in T(A)} g(D) modulo 1,000,000,0071,000,000,007 for all test data will earn 60%60\% of the points for that test case.

Attention: Even if a participant answers only one of the two questions, they must still output two integers in the specified format, corresponding to the answers for both questions.

Input Format

This problem contains multiple test cases.

The first line of input contains two non-negative integers c,tc, t, representing the test case number and the number of test data sets. c=0c = 0 indicates that the test case is a sample.

For each test data set:

  • The first line contains a positive integer nn, the length of the sequence.
  • The second line contains nn positive integers a1,,ana_1, \ldots, a_n, representing sequence AA.
  • The third line contains nn integers b1,,bnb_1, \ldots, b_n, representing sequence BB.
  • The fourth line contains nn positive integers c1,,cnc_1, \ldots, c_n, representing sequence CC.

Output Format

For each test data set, output a single line containing two integers: the maximum value of f(D)f(D) and the sum of g(D)g(D) modulo 1,000,000,0071,000,000,007. Note: maxDT(A)f(D)\max_{D \in T(A)} f(D) does not need to be modulo 1,000,000,0071,000,000,007.

This problem consists of two sub-questions, and correctly answering either will earn partial points. For detailed scoring rules, refer to the [Scoring] section.

Samples

0 3
3
5 6 6
3 6 9
1 2 3
6
1 1 4 5 1 4
-1 1 -1 1 -2 2
1 1 1 1 1 1
8
4 2 4 2 2 2 4 4
-2 4 9 -3 4 8 7 8
1 1 1 1 1 1 1 1
15 10
1 18
37 48

Sample 1 Explanation

This sample contains three test data sets.

For the first test data set, the following 4 sequences can be obtained:

  • D=[5,6,6]D = [5, 6, 6], f(D)=0f(D) = 0, g(D)=1g(D) = 1;
  • D=[0,1,6]D = [0, 1, 6], f(D)=3f(D) = 3, g(D)=1g(D) = 1;
  • D=[5,0,0]D = [5, 0, 0], f(D)=6+9=15f(D) = 6 + 9 = 15, g(D)=2×3=6g(D) = 2 \times 3 = 6;
  • D=[0,0,5]D = [0, 0, 5], f(D)=3+6=9f(D) = 3 + 6 = 9, g(D)=1×2=2g(D) = 1 \times 2 = 2.

Thus, maxDT(A)f(D)=max{0,3,15,9}=15\max_{D \in T(A)} f(D) = \max\{0, 3, 15, 9\} = 15, and DT(A)g(D)=1+1+6+2=10\sum_{D \in T(A)} g(D) = 1 + 1 + 6 + 2 = 10.

Sample 2

See the files sequence/sequence2.in and sequence/sequence2.ans in the contestant directory.

This sample satisfies the constraints of test cases 33 and 44.

Sample 3

See the files sequence/sequence3.in and sequence/sequence3.ans in the contestant directory.

This sample satisfies the constraints of test cases 55 and 66.

Sample 4

See the files sequence/sequence4.in and sequence/sequence4.ans in the contestant directory.

This sample satisfies the constraints of test case 77.

Sample 5

See the files sequence/sequence5.in and sequence/sequence5.ans in the contestant directory.

This sample satisfies the constraints of test cases 1111 and 1212.

Sample 6

See the files sequence/sequence6.in and sequence/sequence6.ans in the contestant directory.

This sample satisfies the constraints of test cases 161816\sim 18.

Data Range

Let NN be the sum of nn across all test data sets in a single test case. For all test data, the following guarantees hold:

  • 1t201 \le t \le 20;
  • 1n5,0001 \le n \le 5,000, N4×104N \le 4 \times 10^4;
  • For all 1in1 \le i \le n, 1Ai1091 \le A_i \le 10^9;
  • For all 1in1 \le i \le n, 109Bi109-10^9 \le B_i \le 10^9;
  • For all 1in1 \le i \le n, 1Ci1091 \le C_i \le 10^9.
Test Case nn \le NN \le Special Properties
1,21, 2 88 10210^2 None
3,43, 4 200200 400400 B
5,65, 6 None
77 500500 10310^3 A
8108 \sim 10 B
11,1211, 12 None
1313 35003\,500 3×1043 \times 10^4 A
14,1514, 15 B
161816 \sim 18 None
19,2019, 20 50005\,000 4×1044 \times 10^4
  • Special Property A: A1=A2==An=1A_1 = A_2 = \cdots = A_n = 1.
  • Special Property B: For all 1in1 \le i \le n, AiA_i is generated independently and uniformly at random from [1,109][1, 10^9].