QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster]

#14977. 櫻之魔法

İstatistikler

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.