AT_arc230_b.Chmax and Chmin
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N, and length-N integer sequences, X=(X1,X2,…,XN) and Y=(Y1,Y2,…,YN).
Additionally, you are given length-N integer sequences, A=(A1,A2,…,AN) and B=(B1,B2,…,BN).
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.
-
chmax: Choose integers l and r such that 1≤l≤r≤N. For i=l,l+1,…,r, replace Ai with max(Ai,Xr−l+1).
-
chmin: Choose integers l and r such that 1≤l≤r≤N. For i=l,l+1,…,r, replace Ai with min(Ai,Yr−l+1).
You are given T test cases; solve each of them.
给你一个正整数 N,以及两个长度为 N 的整数序列 X=(X1,X2,…,XN) 和 Y=(Y1,Y2,…,YN)。
此外,还给出两个长度为 N 的整数序列 A=(A1,A2,…,AN) 和 B=(B1,B2,…,BN)。
请判断是否可以通过执行以下操作(总次数在 0 到 2N 次之间,含端点)使序列 A 变为序列 B;若可以,请输出一种可行的操作方案。
-
chmax:选择满足 1≤l≤r≤N 的整数 l 和 r。对每个 i=l,l+1,…,r,将 Ai 替换为 max(Ai,Xr−l+1)。
-
chmin:选择满足 1≤l≤r≤N 的整数 l 和 r。对每个 i=l,l+1,…,r,将 Ai 替换为 min(Ai,Yr−l+1)。
你将得到 T 组测试数据,请对每组数据求解。
输入格式
The input is given from Standard Input in the following format. Here, testi denotes the i-th test case.
T
test1
test2
⋮
testT
Each test case is given in the following format:
N
X1 X2 … XN
Y1 Y2 … YN
A1 A2 … AN
B1 B2 … BN
输入从标准输入中按以下格式给出。其中,testi 表示第 i 个测试用例。
T
test1
test2
⋮
testT
每个测试用例按以下格式给出:
N
X1 X2 … XN
Y1 Y2 … YN
A1 A2 … AN
B1 B2 … BN
输出格式
For each of the T test cases, in order, output as follows.
If it is impossible to make A match B, output -1.
If it is possible, letting K (0≤K≤2N) be the number of operations performed, output in the following format:
K
op1 l1 r1
op2 l2 r2
⋮
opK lK rK
Here, opi, li, and ri represent the i-th operation. opi is chmax or chmin, representing the type of the i-th operation. li and ri are the l and r chosen in the i-th operation, respectively.
对于每个测试用例(共 T 个),按顺序输出如下内容:
若无法使 A 变为与 B 相同,输出 -1。
若可以实现,则设执行的操作次数为 K (0≤K≤2N),按以下格式输出:
K
op1 l1 r1
op2 l2 r2
⋮
opK lK rK
其中,opi、li 和 ri 表示第 i 次操作。opi 为 chmax 或 chmin,表示第 i 次操作的类型;li 和 ri 分别为第 i 次操作中所选定的 l 和 r。
输入输出样例
输入#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) and B=(3,1,1). Perform the following two operations in order.
-
chmax 1 2: Replace A1,A2 with max(A1,X2)=3,max(A2,X2)=3, respectively. Now A=(3,3,3). -
chmin 2 3: Replace A2,A3 with min(A2,Y2)=1,min(A3,Y2)=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.
Constraints
- 1≤T≤105
- 1≤N≤400
- 1≤Xi,Yi,Ai,Bi≤N
- The sum of N3 over all test cases is at most 4003.
- All input values are integers.
样例 1 解释:
我们解释第一个测试用例。给定 A=(1,2,3) 和 B=(3,1,1)。按顺序执行以下两个操作:
chmax 1 2:将 A1,A2 分别替换为 max(A1,X2)=3,max(A2,X2)=3。此时 A=(3,3,3)。chmin 2 3:将 A2,A3 分别替换为 min(A2,Y2)=1,min(A3,Y2)=1。此时 A=(3,1,1)。
最终,A 与 B 完全一致。以下输出形式同样被接受。
注意:操作次数无需最小化。
对于第二个测试用例,可以证明:不存在长度在 0 到 2N(含端点)之间的操作序列,能使 A 变为 B。
约束条件
- 1≤T≤105
- 1≤N≤400
- 1≤Xi,Yi,Ai,Bi≤N
- 所有测试用例中 N3 的总和不超过 4003。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?