本场比赛其他题目的题解
A. The Miracle and the Sleeper
B. Scenes From a Memory
C. Rings
D1. Two Hundred Twenty One (easy version)
D2. Two Hundred Twenty One (hard version)
D1. Two Hundred Twenty One (easy version)
题目描述
This is the easy version of the problem. The difference between the versions is that the easy version does not 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
n n
n
rods arranged along one straight line and numbered from
1 1
1
to
n n
n
inclusive. Each of these rods must carry an electric charge quantitatively equal to either
1 1
1
or
− 1 -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
n n
n
numbers characterizing the charge: either
1 1
1
or
− 1 -1
−
1
. Then the condition must hold:
a 1 − a 2 + a 3 − a 4 + … = 0 a_1 – a_2 + a_3 – a_4 + \ldots = 0
a
1
−
a
2
+
a
3
−
a
4
+
…
=
0
, or
∑ i = 1 n ( − 1 ) i − 1 ⋅ a i = 0 \sum\limits_{i=1}^n (-1)^{i-1} \cdot a_i = 0
i
=
1
∑
n
(
−
1
)
i
−
1
⋅
a
i
=
0
.
Sparky charged all
n n
n
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
q q
q
questions. In the
i i
i
th question Sparky asks: if the machine consisted only of rods with numbers
l i l_i
l
i
to
r i r_i
r
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? 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!
Input
Each test contains multiple test cases.
The first line contains one positive integer
t ( 1 ≤ t ≤ 1 0 3 ) t\ (1\le t \le 10^3)
t
(
1
≤
t
≤
1
0
3
)
, denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integers
n n
n
and
q q
q
(
1 ≤ n , q ≤ 3 ⋅ 1 0 5 1\le n, q\le 3⋅10^5
1
≤
n
,
q
≤
3
⋅
1
0
5
) — the number of rods and the number of questions.
The second line of each test case contains a non-empty string
s s
s
of length
n n
n
, where the charge of the
i i
i
-th rod is
1 1
1
if
s i s_i
s
i
is the “+” symbol, or
− 1 -1
−
1
if
s i s_i
s
i
is the “-” symbol.
Each next line from the next
q q
q
lines contains two positive integers
l i l_i
l
i
ans
r i r_i
r
i
(
1 ≤ l i ≤ r i ≤ n 1\le l_i\le r_i\le n
1
≤
l
i
≤