#P9870. [NOIP2023] 双序列拓展

    ID: 11153 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP贪心2023NOIP 提高组O2优化Ad-hoc

[NOIP2023] 双序列拓展

Problem Description

A sequence B={b1,b2,,bn}B = \{b_1,b_2,\cdots,b_n\} is called an extension of another sequence A={a1,a2,,am}A = \{a_1,a_2,\cdots,a_m\} if and only if there exists a sequence of positive integers L={l1,l2,,lm}L = \{l_1,l_2,\cdots,l_m\} such that, after replacing aia_i with lil_i copies of aia_i, we obtain the sequence BB. For example:

  • {1,3,3,3,2,2,2}\{1,3,3,3,2,2,2\} is an extension of {1,3,3,2}\{1,3,3,2\}, with L={1,1,2,3}L = \{1,1,2,3\} or {1,2,1,3}\{1,2,1,3\}.
  • However, {1,3,3,2}\{1,3,3,2\} is not an extension of {1,3,3,3,2}\{1,3,3,3,2\}, and {1,2,3}\{1,2,3\} is not an extension of {1,3,2}\{1,3,2\}.

Little R gives you two sequences XX and YY. He wants you to find an extension F={fi}F = \{f_i\} of XX with length l0=10100l_0 = 10^{100} and an extension G={gi}G = \{g_i\} of YY with length l0l_0, such that for any 1i,jl01 \le i , j \le l_0, we have (figi)(fjgj)>0(f_i - g_i)(f_j - g_j) > 0. Since the sequences are too long, you only need to tell Little R whether such two sequences exist.

To prevent you from just guessing, Little R also gives qq additional queries. In each additional query, Little R will modify the values of some elements in XX and YY. For each new XX and YY, you need to make the above decision again.

The queries are independent. In each query, all modifications are applied to the original sequences.

Input Format

The first line contains four integers c,n,m,qc, n, m, q, representing the test point index, the length of sequence XX, the length of sequence YY, and the number of additional queries. For the samples, cc indicates that the sample has the same constraints as test point cc.

The second line contains nn integers x1,x2,,xnx_1,x_2,\cdots, x_n, describing sequence XX.

The third line contains mm integers y1,y2,,ymy_1,y_2,\cdots, y_m, describing sequence YY.

Next, qq groups of additional queries are given. For each group:

  • The first line contains two integers kxk_x and kyk_y, representing the numbers of modifications to sequences XX and YY, respectively.
  • The next kxk_x lines each contain two integers px,vxp_x, v_x, meaning setting xpxx_{p_x} to vxv_x.
  • The next kyk_y lines each contain two integers py,vyp_y, v_y, meaning setting ypyy_{p_y} to vyv_y.

Output Format

Output one line containing a 01 sequence of length (q+1)(q+1). The first element is the answer for the initial query, and the following qq elements are the answers for the additional queries in order. For each query, if there exist sequences FF and GG that satisfy the conditions, output 1; otherwise output 0.

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

1001

Hint

[Sample Explanation #1]

Since FF and GG are too long, we use ellipses to indicate repeating the last element until the sequence length reaches l0l_0. For example, {1,2,3,3,}\{1,2,3,3,\cdots\} means that all elements after the third one are 33.

The following describes four queries in order. The first is the initial query, and the next three are additional queries:

  1. A={8,6,9}A = \{8,6,9\}, B={1,7,4}B = \{1,7,4\}. Take F={8,8,6,9,},G={1,7,4,4,}F = \{8,8,6,9,\cdots\}, G = \{1,7,4,4,\cdots\}.
  2. A={8,6,0}A = \{8,6,0\}, B={1,7,4}B = \{1,7,4\}. It can be proven that no solution satisfies the requirement.
  3. A={8,6,9}A = \{8,6,9\}, B={8,7,5}B = \{8,7,5\}. It can be proven that no solution satisfies the requirement.
  4. A={8,8,9}A = \{8,8,9\}, B={7,7,4}B = \{7,7,4\}. Take F={8,8,9,},G={7,7,4,}F = \{8,8,9,\cdots\}, G = \{7,7,4,\cdots\}.

[Sample Explanation #2]

This sample satisfies the constraints of test point 44.

[Sample Explanation #3]

This sample satisfies the constraints of test point 77.

[Sample Explanation #4]

This sample satisfies the constraints of test point 99.

[Sample Explanation #5]

This sample satisfies the constraints of test point 1818.

[Constraints]

For all testdata, it is guaranteed that:

  • 1n,m5×1051 \le n, m \le 5 \times 10 ^ 5.
  • 0q600 \le q \le 60.
  • 0xi,yi<1090 \le x_i, y_i < 10 ^ 9.
  • 0kx,ky5×1050 \le k_x, k_y \le 5 \times 10 ^ 5, and the sum of (kx+ky)(k_x+k_y) over all additional queries does not exceed 5×1055 \times 10 ^ 5.
  • 1pxn1 \le p_x \le n, 1pym1 \le p_y \le m, 0vx,vy<1090 \le v_x, v_y < 10 ^ 9.
  • For each additional query, all pxp_x are pairwise distinct, and all pyp_y are pairwise distinct.
Test Point Index n,mn, m \le Special Property
11 No
22
3,43, 4 66
55 200200
6,76, 7 20002000
8,98, 9 4×1044 \times 10 ^ 4 Yes
10,1110, 11 1.5×1051.5 \times 10 ^ 5
121412 \sim 14 5×1055 \times 10 ^ 5
15,1615, 16 4×1044 \times 10 ^ 4 No
17,1817, 18 1.5×1051.5 \times 10 ^ 5
19,2019, 20 5×1055 \times 10 ^ 5

Special property: For each query (including the initial query and additional queries), it is guaranteed that x1<y1x_1 < y_1, and xnx_n is the unique minimum value in sequence XX, while ymy_m is the unique maximum value in sequence YY.

Translated by ChatGPT 5