AT_arc230_b.Chmax and Chmin

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN, and length-NN integer sequences, X=(X1,X2,…,XN)X=(X_1,X_2,\dots ,X_N) and Y=(Y1,Y2,…,YN)Y=(Y_1,Y_2,\dots ,Y_N).

Additionally, you are given length-NN integer sequences, A=(A1,A2,…,AN)A=(A_1,A_2,\dots ,A_N) and B=(B1,B2,…,BN)B=(B_1,B_2,\dots ,B_N).

Determine whether it is possible to make AA match BB by performing the following operations any number of times between 00 and 2N2N (inclusive) in total, and if it is possible, output one such procedure.

  • chmax: Choose integers ll and rr such that 1≤l≤r≤N1\le l\le r\le N. For i=l,l+1,…,ri=l,l+1,\dots ,r, replace AiA_i with max⁡(Ai,Xr−l+1)\max(A_i,X_{r-l+1}).

  • chmin: Choose integers ll and rr such that 1≤l≤r≤N1\le l\le r\le N. For i=l,l+1,…,ri=l,l+1,\dots ,r, replace AiA_i with min⁡(Ai,Yr−l+1)\min(A_i,Y_{r-l+1}).

You are given TT test cases; solve each of them.

给你一个正整数 NN,以及两个长度为 NN 的整数序列 X=(X1,X2,…,XN)X=(X_1,X_2,\dots ,X_N) 和 Y=(Y1,Y2,…,YN)Y=(Y_1,Y_2,\dots ,Y_N)。

此外,还给出两个长度为 NN 的整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots ,A_N) 和 B=(B1,B2,…,BN)B=(B_1,B_2,\dots ,B_N)。

请判断是否可以通过执行以下操作(总次数在 00 到 2N2N 次之间,含端点)使序列 AA 变为序列 BB;若可以,请输出一种可行的操作方案。

  • chmax:选择满足 1≤l≤r≤N1\le l\le r\le N 的整数 ll 和 rr。对每个 i=l,l+1,…,ri=l,l+1,\dots ,r,将 AiA_i 替换为 max⁡(Ai,Xr−l+1)\max(A_i,X_{r-l+1})。

  • chmin:选择满足 1≤l≤r≤N1\le l\le r\le N 的整数 ll 和 rr。对每个 i=l,l+1,…,ri=l,l+1,\dots ,r,将 AiA_i 替换为 min⁡(Ai,Yr−l+1)\min(A_i,Y_{r-l+1})。

你将得到 TT 组测试数据,请对每组数据求解。

输入格式

The input is given from Standard Input in the following format. Here, testi\mathrm{test}_i denotes the ii-th test case.

TT
test1\mathrm{test}_1
test2\mathrm{test}_2
⋮\vdots
testT\mathrm{test}_T

Each test case is given in the following format:

NN
X1X_1 X2X_2 …\dots XNX_N
Y1Y_1 Y2Y_2 …\dots YNY_N
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BNB_N

输入从标准输入中按以下格式给出。其中,testi\mathrm{test}_i 表示第 ii 个测试用例。

TT
test1\mathrm{test}_1
test2\mathrm{test}_2
⋮\vdots
testT\mathrm{test}_T

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

NN
X1X_1 X2X_2 …\dots XNX_N
Y1Y_1 Y2Y_2 …\dots YNY_N
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BNB_N

输出格式

For each of the TT test cases, in order, output as follows.

If it is impossible to make AA match BB, output -1.

If it is possible, letting K (0≤K≤2N)K\ (0\le K\le 2N) be the number of operations performed, output in the following format:

KK
op1\mathrm{op}_1 l1l_1 r1r_1
op2\mathrm{op}_2 l2l_2 r2r_2
⋮\vdots
opK\mathrm{op}_K lKl_K rKr_K

Here, opi\mathrm{op}_i, lil_i, and rir_i represent the ii-th operation. opi\mathrm{op}_i is chmax or chmin, representing the type of the ii-th operation. lil_i and rir_i are the ll and rr chosen in the ii-th operation, respectively.

对于每个测试用例(共 TT 个),按顺序输出如下内容:

若无法使 AA 变为与 BB 相同,输出 -1。

若可以实现,则设执行的操作次数为 K (0≤K≤2N)K\ (0\le K\le 2N),按以下格式输出:

KK
op1\mathrm{op}_1 l1l_1 r1r_1
op2\mathrm{op}_2 l2l_2 r2r_2
⋮\vdots
opK\mathrm{op}_K lKl_K rKr_K

其中,opi\mathrm{op}_i、lil_i 和 rir_i 表示第 ii 次操作。opi\mathrm{op}_i 为 chmax 或 chmin,表示第 ii 次操作的类型;lil_i 和 rir_i 分别为第 ii 次操作中所选定的 ll 和 rr。

输入输出样例

  • 输入#1

    2
    3
    1 3 1
    3 1 3
    1 2 3
    3 1 1
    2
    1 1
    2 2
    1 2
    2 1

    输出#1

    2
    chmax 1 2
    chmin 2 3
    -1 4
    chmax 1 3
    chmax 1 2
    chmin 1 1
    chmin 2 3

说明/提示

Sample 1 Explanation:
We explain the first test case. We have A=(1,2,3)A=(1,2,3) and B=(3,1,1)B=(3,1,1). Perform the following two operations in order.

  • chmax 1 2 : Replace A1,A2A_1,A_2 with max⁡(A1,X2)=3,max⁡(A2,X2)=3\max(A_1,X_2)=3,\max(A_2,X_2)=3, respectively. Now A=(3,3,3)A=(3,3,3).

  • chmin 2 3 : Replace A2,A3A_2,A_3 with min⁡(A2,Y2)=1,min⁡(A3,Y2)=1\min(A_2,Y_2)=1,\min(A_3,Y_2)=1, respectively. Now A=(3,1,1)A=(3,1,1).

As a result, AA matches BB. The following output is also accepted.

Note that the number of operations does not need to be minimized.

For the second test case, it can be shown that no sequence of operations of length between 00 and 2N2N (inclusive) makes AA match BB.

Constraints

  • 1≤T≤1051 \le T \le 10^5
  • 1≤N≤4001 \le N \le 400
  • 1≤Xi,Yi,Ai,Bi≤N1 \le X_i,Y_i,A_i,B_i\le N
  • The sum of N3N^3 over all test cases is at most 4003400^3.
  • All input values are integers.

样例 1 解释:
我们解释第一个测试用例。给定 A=(1,2,3)A=(1,2,3) 和 B=(3,1,1)B=(3,1,1)。按顺序执行以下两个操作:

  • chmax 1 2:将 A1,A2A_1,A_2 分别替换为 max⁡(A1,X2)=3,max⁡(A2,X2)=3\max(A_1,X_2)=3,\max(A_2,X_2)=3。此时 A=(3,3,3)A=(3,3,3)。
  • chmin 2 3:将 A2,A3A_2,A_3 分别替换为 min⁡(A2,Y2)=1,min⁡(A3,Y2)=1\min(A_2,Y_2)=1,\min(A_3,Y_2)=1。此时 A=(3,1,1)A=(3,1,1)。

最终,AA 与 BB 完全一致。以下输出形式同样被接受。

注意:操作次数无需最小化。

对于第二个测试用例,可以证明:不存在长度在 00 到 2N2N(含端点)之间的操作序列,能使 AA 变为 BB。

约束条件

  • 1≤T≤1051 \le T \le 10^5
  • 1≤N≤4001 \le N \le 400
  • 1≤Xi,Yi,Ai,Bi≤N1 \le X_i,Y_i,A_i,B_i\le N
  • 所有测试用例中 N3N^3 的总和不超过 4003400^3。
  • 所有输入值均为整数。

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

首页