QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show]

#14977. 樱之魔法

Statistics

Una 正在一条有 $n$ 棵樱花树的路上行走,春天的碎片从空中轻轻飘落。第 $i$ 棵樱花树上有 $a_i$ 朵花。

Una 非常想念她最好的朋友 Kamome。她记得,在 Kamome 离开这座城镇的那天,Kamome 给了 Una 一个整数序列 $b_1, \dots, b_n$。Kamome 告诉 Una,当对所有 $i \in [1, n]$ 都有 $a_i \equiv b_i \pmod 2$ 时,樱花树中的魔法力量就会被激活,她们就能再次重逢。

Una 的愿望如此强烈,以至于她的想象变成了现实。她获得了让花朵盛开的魔法力量。每次挥动魔杖时,她可以选择樱花树的一个连续子段 $[l, r]$,并将其中每个 $i \in [l, r]$ 的 $a_i$ 同时变为 $\sum_{j=l}^i a_j$。

拥有魔法天赋的 Una 每天可以施展任意次数的魔法,但她在同一天内不能对同一棵树施展两次或更多次魔法,否则这棵树会因为承受过量的魔力而枯死。(换句话说,同一天选择的子段两两不能相交。)

Una 已经十年没有见过 Kamome 了,她不想再等下去了。Una 想知道她们重逢所需的最少天数(即让每个 $i \in [1, n]$ 都满足 $a_i \equiv b_i \pmod 2$),以及为了达到这一最少天数她每天应该施展怎样的魔法。注意这可能是无法做到的,此时你应当告诉她这一事实。(更多细节请参阅输出格式部分。)

输入格式

每个测试点包含多组测试数据。第一行包含测试数据组数 $t$($1 \le t \le 2.5 \times 10^4$)。接下来是各组测试数据的描述。

每组测试数据的第一行包含一个整数 $n$($1 \le n \le 10^3$,$\sum n^2 \le 10^6$),表示樱花树的数量。

每组测试数据的第二行包含 $n$ 个整数 $a_1, \dots, a_n$($0 \le a_i \le 1$),表示当前每棵树上的花朵数量。

每组测试数据的第三行包含 $n$ 个整数 $b_1, \dots, b_n$($0 \le b_i \le 1$),表示 Kamome 给 Una 的序列。

输出格式

对于每组测试数据,如果无法让 Kamome 和 Una 重逢,输出 -1。否则,先输出一个整数 $k$,表示 Una 与 Kamome 重逢所需的最少天数。

在接下来的 $k$ 行中的第 $i$ 行,你需要给出 Una 在第 $i$ 天应当执行的魔法指令。你需要输出 $2c + 1$ 个整数 $c_i, l_{i,1}, r_{i,1}, l_{i,2}, r_{i,2}, \dots, l_{i,c}, r_{i,c}$,其中 $c$ 是她在第 $i$ 天执行的魔法操作次数,$[l_{i,j}, r_{i,j}]$ 表示她在第 $i$ 天选择的第 $j$ 个连续子段。你需要保证对所有 $1 \le i \le c - 1$ 有 $r_i < l_{i+1}$,且对所有 $1 \le i \le c$ 有 $l_i \le r_i$。

如果有多种合法方案,你可以输出其中任意一种。

样例

输入

3
5
1 0 1 0 1
0 1 0 1 0
3
1 1 0
1 1 1
10
1 0 0 1 0 1 0 0 1 0
1 0 1 0 0 1 0 1 0 0

输出

-1
1
1 2 3
2
2 1 4 6 9
2 1 2 6 7

说明

在第三组测试数据中,第一天结束时,序列 $a$ 为 $[\underline{1, 1, 1, 2}, 0, \underline{1, 1, 1, 2}, 0]$。

第二天结束时,序列 $a$ 为 $[\underline{1, 2}, 1, 2, 0, \underline{1, 2}, 1, 2, 0]$。

显然两天后有 $a_i \equiv b_i \pmod 2$。可以证明无法在一天之内达成目标。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.