#P16592. [GKS 2016 #E] Diwali lightings

    ID: 16565 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>数学2016前缀和差分Google Kick Start

[GKS 2016 #E] Diwali lightings

题目描述

Diwali is the festival of lights. To celebrate it, people decorate their houses with multi-color lights and burst crackers. Everyone loves Diwali, and so does Pari. Pari is very fond of lights, and has transfinite powers, so she buys an infinite number of red and blue light bulbs. As a programmer, she also loves patterns, so she arranges her lights by infinitely repeating a given finite pattern SS.

For example, if SS is BBRB, the infinite sequence Pari builds would be BBRBBBRBBBRB... .

Blue is Pari's favorite color, so she wants to know the number of blue bulbs between the Ith bulb and Jth bulb, inclusive, in the infinite sequence she built (lights are numbered with consecutive integers starting from 1). In the sequence above, the indices would be numbered as follows:

B B R B B B R B B B  R  B...
1 2 3 4 5 6 7 8 9 10 11 12

So, for example, there are 44 blue lights between the 44th and 88th positions, but only 22 between the 1010th and 1212th.

Since the sequence can be very long, she wrote a program to do the count for her. Can you do the same?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. First line of each test case consists of a string SS, denoting the initial finite pattern. Second line of each test case consists of two space separated integers II and JJ, defined above.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is number of blue bulbs between the Ith bulb and Jth bulb of Pari's infinite sequence, inclusive.

3
BBRB
4 8
BBRB
10 12
BR
1 1000000
Case #1: 4
Case #2: 2
Case #3: 500000

提示

Cases #1 and #2 are explained above.

In Case #3, bulbs at odd indices are always blue, and bulbs at even indices are always red, so there are half a million blue bulbs between positions 1 and 10610^6.

Limits

1T1001 \le T \le 100.

11 \le length of S100S \le 100.

Each character of SS is either uppercase B or uppercase R.

Small dataset (Test set 1 - Visible)

1IJ1061 \le I \le J \le 10^6.

Large dataset (Test set 2 - Hidden)

1IJ10181 \le I \le J \le 10^{18}.