第 230 场 AtCoder Regular Contest++
B
Chmax 与 Chmin
Chmax and Chmin
AtCoder
⌀ 2632
原题
← AC →

Chmax 与 ChminAI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a positive integer $N$, and length-$N$ integer sequences, $X=(X_1,X_2,\dots ,X_N)$ and $Y=(Y_1,Y_2,\dots ,Y_N)$.

给定一个正整数 $N$,以及两个长度为 $N$ 的整数序列 $X=(X_1,X_2,\dots ,X_N)$ 和 $Y=(Y_1,Y_2,\dots ,Y_N)$。AI (CI翻译)

Additionally, you are given length-$N$ integer sequences, $A=(A_1,A_2,\dots ,A_N)$ and $B=(B_1,B_2,\dots ,B_N)$.

此外,还给定两个长度为 $N$ 的整数序列 $A=(A_1,A_2,\dots ,A_N)$ 和 $B=(B_1,B_2,\dots ,B_N)$。AI (CI翻译)

Determine whether it is possible to make $A$ match $B$ by performing the following operations any number of times between $0$ and $2N$ (inclusive) in total, and if it is possible, output one such procedure.

请判断是否可以通过执行总次数在 $0$ 次到 $2N$ 次(包含端点)的以下操作,使 $A$ 变为 $B$。如果可以,请输出一种操作方案。AI (CI翻译)

  • chmax: Choose integers $l$ and $r$ such that $1\le l\le r\le N$. For $i=l,l+1,\dots ,r$, replace $A_i$ with $\max(A_i,X_{r-l+1})$.
  • chmin: Choose integers $l$ and $r$ such that $1\le l\le r\le N$. For $i=l,l+1,\dots ,r$, replace $A_i$ with $\min(A_i,Y_{r-l+1})$.
  • chmax:选择整数 $l$ 和 $r$,满足 $1\le l\le r\le N$。对于 $i=l,l+1,\dots ,r$,将 $A_i$ 替换为 $\max(A_i,X_{r-l+1})$。
  • chmin:选择整数 $l$ 和 $r$,满足 $1\le l\le r\le N$。对于 $i=l,l+1,\dots ,r$,将 $A_i$ 替换为 $\min(A_i,Y_{r-l+1})$。
AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 个测试用例,请分别求解每个测试用例。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le T \le 10^5$
  • $1 \le N \le 400$
  • $1 \le X_i,Y_i,A_i,B_i\le N$
  • The sum of $N^3$ over all test cases is at most $400^3$.
  • All input values are integers.
  • $1 \le T \le 10^5$
  • $1 \le N \le 400$
  • $1 \le X_i,Y_i,A_i,B_i\le N$
  • 所有测试用例的 $N^3$ 之和不超过 $400^3$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入给出,格式如下。其中,$\mathrm{test}_i$ 表示第 $i$ 个测试用例。AI (CI翻译)

T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T

T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T
AI (CI翻译)

Each test case is given in the following format:

每个测试用例的格式如下:AI (CI翻译)

N
X_1 X_2 \dots X_N
Y_1 Y_2 \dots Y_N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

N
X_1 X_2 \dots X_N
Y_1 Y_2 \dots Y_N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

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

对于每个测试用例,按输入顺序输出如下内容。AI (CI翻译)

If it is impossible to make $A$ match $B$, output -1.

如果无法使 $A$ 变为 $B$,输出 -1。AI (CI翻译)

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

如果可以,令 $K\ (0\le K\le 2N)$ 为执行的操作次数,按照以下格式输出:AI (CI翻译)

K
\mathrm{op}_1 l_1 r_1
\mathrm{op}_2 l_2 r_2
\vdots
\mathrm{op}_K l_K r_K

K
\mathrm{op}_1 l_1 r_1
\mathrm{op}_2 l_2 r_2
\vdots
\mathrm{op}_K l_K r_K
AI (CI翻译)

Here, $\mathrm{op}_i$, $l_i$, and $r_i$ represent the $i$-th operation. $\mathrm{op}_i$ is chmax or chmin, representing the type of the $i$-th operation. $l_i$ and $r_i$ are the $l$ and $r$ chosen in the $i$-th operation, respectively.

其中,$\mathrm{op}_i$、$l_i$ 和 $r_i$ 分别表示第 $i$ 个操作及其所选择的区间端点。$\mathrm{op}_i$ 为 chmax 或 chmin,表示第 $i$ 个操作的类型。$l_i$ 和 $r_i$ 分别为第 $i$ 个操作中选择的 $l$ 和 $r$。AI (CI翻译)

样例

Input #1
2
3
1 3 1
3 1 3
1 2 3
3 1 1
2
1 1
2 2
1 2
2 1
Output #1
2
chmax 1 2
chmin 2 3
-1
We explain the first test case. We have $A=(1,2,3)$ and $B=(3,1,1)$. Perform the following two operations in order. - `chmax 1 2` : Replace $A_1,A_2$ with $\max(A_1,X_2)=3,\max(A_2,X_2)=3$, respectively. Now $A=(3,3,3)$. - `chmin 2 3` : Replace $A_2,A_3$ with $\min(A_2,Y_2)=1,\min(A_3,Y_2)=1$, respectively. Now $A=(3,1,1)$. As a result, $A$ matches $B$. 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 $0$ and $2N$ (inclusive) makes $A$ match $B$.
题目信息
题号
arc230_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。