#P4497. [WC2011] 拼点游戏

[WC2011] 拼点游戏

Description

Xiao W and Xiao Y both enjoy a “point-picking game.” In the game, each of the two players produces a number as their “score” through some operation, and the player with the larger score wins. The rules of the “point-picking game” are as follows:

  1. At the start of the game, you are given a positive integer sequence with nn elements, U=(u1,u2,,un)U=(u_1, u_2, \cdots, u_n).
  2. An index sequence I=(i1,i2,,im)I=(i_1, i_2, \cdots, i_m) of UU is an integer sequence satisfying 1i1<i2<<imn1 \leq i_1 < i_2 < \cdots < i_m \leq n (where mm can be 00, i.e., the sequence can be empty), and its corresponding subsequence of UU is V=(ui1,ui2,,uim)V=(u_{i_1}, u_{i_2}, \cdots, u_{i_m}).
  3. The score D(I)D(I) corresponding to the index sequence I=(i1,i2,,im)I=(i_1, i_2, \cdots, i_m) is defined as D(I)=p=1muip×(1)pD(I)=\sum_{p=1}^m u_{i_p} \times (-1)^p.
  4. During the game, the two players each choose an index sequence, and the one whose chosen index sequence corresponds to a larger score D(I)D(I) wins.

However, in every game, Xiao W can always compute, accurately and flawlessly, the optimal index sequence that maximizes the score. To make the game more competitive, they added the following extra rules:

Ex1. Xiao W may choose a non-empty interval [l,r][l, r] and increase ul,ul+1,,uru_l, u_{l+1}, \cdots, u_r by an integer cc simultaneously; the new sequence replaces the original sequence UU.

Ex2. When they play a “point-picking game” on the current sequence UU, Xiao Y is allowed, after Xiao W has chosen the optimal index sequence IW=(i1,i2,,im)I_W=(i_1, i_2, \cdots, i_m), to modify IWI_W any number of times. Each modification follows the rules below: (1) Arbitrarily choose a positive integer kk satisfying 2k+1m2k+1 \leq m, and two non-negative integers z1,z2z_1, z_2 satisfying i2k+z1<i2k+1z2i_{2k} + z_1 < i_{2k+1} - z_2; (2) Change i2ki_{2k} to i2k+z1i_{2k} + z_1, and change i2k+1i_{2k+1} to i2k+1z2i_{2k+1} - z_2.

If, after some number of modifications by Xiao Y to the index sequence IWI_W chosen by Xiao W, the corresponding score is less than or equal to 00, then Xiao Y wins.

Now, given the information about Xiao W’s Ex1 operations, for each “point-picking game,” please help them compute: a) What is the score of the optimal index sequence that Xiao W can initially choose? b) What is the minimum number of modification operations Xiao Y needs in order to win, i.e., to make D(IW)0D(I_W) \leq 0?

Input Format

The first line of the input file joy.in contains a positive integer TT, the number of groups of testdata. Then follow TT groups of data.

For each group of data, the first line contains two integers nn and qq, denoting the number of elements in UU and the number of events, respectively.

The next line contains nn positive integers separated by single spaces, where the ii-th integer is the ii-th element uiu_i in the initial sequence.

The following qq lines each describe an event (given in chronological order). The first number in each line is either 00 or 11, indicating the type of the event.

If it is 00: after the 00 there are three integers ll, rr, and cc (all separated by single spaces), meaning Xiao W increases ul,ul+1,,uru_l, u_{l+1}, \cdots, u_r by cc.

If it is 11: the two players play a “point-picking game,” and you need to output the corresponding result.

The input guarantees that all elements in the sequence UU are always positive integers.

Output Format

The output file is joy.out. For each group of testdata, for each “point-picking game” in order, output one line containing two integers separated by a single space, DmaxD_{max} and XX, where

  • DmaxD_{max} is the score of the optimal index sequence that Xiao W can choose for the current sequence UU;
  • XX is the minimum number of modification operations that Xiao Y needs to win. If Xiao Y cannot win no matter how many operations are performed, output -1.

The data guarantee that the optimal index sequence is always unique.

2 
5 9 
9 10 7 6 8 
1 
0 4 5 2 
0 3 5 4 
1 
0 2 5 -2 
0 3 5 -3 
0 4 5 -2 
0 5 5 -4 
1 
4 3 
2 4 3 5 
1 
0 3 3 3 
1 
3 1 
5 -1 
0 0 
4 -1 
4 -1 

Hint

Scoring rules:

  • A test point contains multiple groups of testdata. For that test point:
    • If all DmaxD_{max} are correct but some XX is incorrect, you get 3 points.
    • If all XX are correct but some DmaxD_{max} is incorrect, you get 7 points.
    • If all answers are correct, you get 10 points.

Sample explanation:

  • The input contains two groups of testdata.
  • In the first group: In the first “point-picking game,” the optimal index sequence is (1,2,4,5)(1, 2, 4, 5). Xiao Y needs only one modification: choose k=1k=1 and non-negative integers z1=1z_1=1, z2=0z_2=0. After the modification, the index sequence becomes (1,3,4,5)(1, 3, 4, 5), and Xiao Y wins.
  • In the third “point-picking game,” the sequence UU is (9,8,6,5,3)(9, 8, 6, 5, 3). Xiao W chooses the empty sequence as the optimal index sequence, yielding a score of 00. In this case, Xiao Y cannot make any modification (nor is any modification needed), and Xiao Y already wins.

Constraints:

  • For 10% of the data, n,q13n, q \leq 13.
  • For 30% of the data, n,q1000n, q \leq 1000.
  • For another 20% of the data, T=1T=1 and n40000n \leq 40000.
  • For 100% of the data, T3T \leq 3 and n,q105n, q \leq 10^5, and the initial sequence UU satisfies 0<ui<2310 < u_i < 2^{31} and c<105|c| < 10^5.

Translated by ChatGPT 5