CF1562D2.Two Hundred Twenty One (hard version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the hard version of the problem. The difference between the versions is that the hard version does require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.

Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.

The main element of this machine are nn rods arranged along one straight line and numbered from 11 to nn inclusive. Each of these rods must carry an electric charge quantitatively equal to either 11 or 1-1 (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.

More formally, the rods can be represented as an array of nn numbers characterizing the charge: either 11 or 1-1 . Then the condition must hold: a1a2+a3a4+=0a_1 - a_2 + a_3 - a_4 + \ldots = 0 , or i=1n(1)i1ai=0\sum\limits_{i=1}^n (-1)^{i-1} \cdot a_i = 0 .

Sparky charged all nn rods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has qq questions. In the ii th question Sparky asks: if the machine consisted only of rods with numbers lil_i to rir_i inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Also Sparky wants to know the numbers of these rods. Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don't have to remove the rods at all.

If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.

Help your friends and answer all of Sparky's questions!

输入格式

Each test contains multiple test cases.

The first line contains one positive integer tt ( 1t1031 \le t \le 10^3 ), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains two positive integers nn and qq ( 1n,q31051 \le n, q \le 3 \cdot 10^5 ) — the number of rods and the number of questions.

The second line of each test case contains a non-empty string ss of length nn , where the charge of the ii -th rod is 11 if sis_i is the "+" symbol, or 1-1 if sis_i is the "-" symbol.

Each next line from the next qq lines contains two positive integers lil_i ans rir_i ( 1lirin1 \le l_i \le r_i \le n ) — numbers, describing Sparky's questions.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5 , and the sum of qq over all test cases does not exceed 31053 \cdot 10^5 .

It is guaranteed that the sum of the answers (minimal number of rods that can be removed) over all test cases does not exceed 10610^6 .

输出格式

For each test case, print the answer in the following format:

In the first line print a single integer kk — the minimal number of rods that can be removed.

In the second line print kk numbers separated by a space — the numbers of rods to be removed.

If there is more than one correct answer, you can print any.

输入输出样例

  • 输入#1

    3
    14 1
    +--++---++-++-
    1 14
    14 3
    +--++---+++---
    1 14
    6 12
    3 10
    4 10
    +-+-
    1 1
    1 2
    1 3
    1 4
    2 2
    2 3
    2 4
    3 3
    3 4
    4 4

    输出#1

    2
    5 8
    2
    1 11
    1
    9
    0
    1
    1
    2
    1 2
    1
    2
    2
    1 3
    1
    2
    2
    2 3
    1
    3
    1
    3
    2
    3 4
    1
    4

说明/提示

In the first test case for the first query you can remove the rods numbered 55 and 88 , then the following set of rods will remain: +--+----. It is easy to see that here the sign-variable sum is zero.

In the second test case:

  • For the first query, we can remove the rods numbered 11 and 1111 , then the following set of rods will remain: --------. It is easy to see that here the sign-variable sum is zero.
  • For the second query we can remove the rod numbered 99 , then the following set of rods will remain: ---++-. It is easy to see that here the variable sum is zero.
  • For the third query we can not remove the rods at all.
首页