#P3785. [SDOI2017] 文本校正

    ID: 2727 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2017各省省选山东Special JudgeO2优化

[SDOI2017] 文本校正

Description

While developing a data obfuscation algorithm, Xiao Q accidentally obfuscated some important documents. Fortunately, correcting these documents is not difficult for him. With keen observation, he managed to correct them by eye.

To prevent this from happening again, Xiao Q wants to develop a text correction tool. His goal is to split a string TT into three consecutive segments, each of which must be non-empty, then concatenate these 3 segments from left to right in some order to restore the original string SS.

After a lot of manual correction, Xiao Q needs a break, so he assigns this task to you. Please write a program to determine whether restoration is possible, and if so, output a valid restoration plan.

Input Format

The first line contains a positive integer CaseCase, the number of correction tasks.

Then follow CaseCase parts, each describing one task. The first line of each part contains two positive integers nn, mm, denoting the length of the string and the size of the character set, respectively.

The second line of each part contains nn positive integers S1,S2,,SnS_1, S_2, \dots, S_n, representing the string SS.

The third line of each part contains nn positive integers T1,T2,,TnT_1, T_2, \dots, T_n, representing the string TT.

Output Format

For each task, if there is no solution, output a single line "NO" (without quotes). Otherwise, output "YES" (without quotes) on the first line, and then output three lines, each containing two positive integers lil_i, rir_i, representing the 3 substrings of TT in the concatenation order.

If multiple restoration plans exist, output any one of them.

3
5 3
2 1 1 1 1
1 1 1 1 2
5 5
5 2 3 3 4
2 5 3 4 3
5 5
4 5 2 1 4
5 4 2 1 4
YES
5 5
1 3
4 4
NO
YES
2 2
1 1
3 5

Hint

Constraints: For 100%100\% of the testdata, 3n10000003 \leq n \leq 1000000, 1Si,Tim10000001 \leq S_i, T_i \leq m \leq 1000000.

spj by @Wen_kr.

Translated by ChatGPT 5