AT_arc230_b [ARC230B] Chmax and Chmin
Description
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) $ .
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) $ .
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\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}) $ .
You are given $ T $ test cases; solve each of them.
Input Format
The input is given from Standard Input in the following format. Here, $ \mathrm{test}_i $ denotes the $ i $ -th test case.
> $ T $ $ \mathrm{test}_1 $ $ \mathrm{test}_2 $ $ \vdots $ $ \mathrm{test}_T $
Each test case is given in the following format:
> $ 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 $
Output Format
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\le K\le 2N) $ be the number of operations performed, output in the following format:
> $ K $ $ \mathrm{op}_1 $ $ l_1 $ $ r_1 $ $ \mathrm{op}_2 $ $ l_2 $ $ r_2 $ $ \vdots $ $ \mathrm{op}_K $ $ l_K $ $ r_K $
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.
Explanation/Hint
### Sample Explanation 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.
```
4
chmax 1 3
chmax 1 2
chmin 1 1
chmin 2 3
```
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 \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.