WBC '25 P4 - Raffle Tickets
View as PDFWelcome Back Contest: 2025 Problem 4
Alice, who is not in wonderland, would like to go, so she enters into a raffle for a chance to go for free! She gets a connected strip of raffle tickets, each with an number written on it. The raffle is quite strange, allowing for multiple tickets to have the same number so that multiple people can win with the same number. She numbers the tickets from
to
from left to right, which she calls their index. While she is waiting for the raffle draw, she wonders the following:
Define a "connected group" of tickets to be all the tickets with indices from
to
inclusive. Two connected groups of tickets are said to be different if their starting or ending index differs.
If you are given indices
and
, how many distinct connected groups of tickets exist in that range such that the sum of their numbers are even?
Alice needs your help to answer her questions!
Input Specification
The first line contains the integers ,
, each separated by a space.
The next line contains the numbers written on the raffle tickets, from left to right, each separated by a space.
The next lines contains indices
and
for the
-th question.
Output Specification
For each question, output the answer on its own line.
Constraints
Sample Input 1
5 3
2 1 3 2 3
2 4
1 5
3 5
Output for Sample Input 1
3
7
2
Explanation of Output for Sample Input 1
For the first question, you are given and
, which represents the tickets
. The
connected groups that have even sums that exist within this range are
,
, and
.
For the second question, you are given and
which represents the tickets
. The
connected groups that have even sums that exist within this range are
,
,
,
,
,
,
. Notice that
appears twice, as there are
different connected groups that look identical.
For the third question, you are given and
, which represents the tickets
. The
connected groups that have even sums that exist within this range are
, and
.
Sample Input 2
9 5
2 1 3 5 2 4 4 2 3
1 9
3 6
2 2
5 8
4 7
Output for Sample Input 2
21
6
0
10
6
Comments