#PS0000111. Đĩa giữa những ngọn nến (Plates Between Candles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đĩa giữa những ngọn nến (Plates Between Candles)
Plates Between Candles
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A row of plates and candles on a table is represented by a zero-indexed string : * denotes a plate and | a candle. For a query , consider only positions through , inclusive. Count plates having a candle somewhere on each side, with both candles inside the queried substring.
Input
The first line contains integers , the string length and number of queries.
The second line contains .
Each of the following lines contains zero-based indices .
Output
Print lines, each containing the count for the corresponding query.
Subtasks
- Subtask 1 (20 points): ; ; ; Each character is
*or|; . - Subtask 2 (30 points): ; ; ; Each character is
*or|; ; . - Subtask 3 (50 points): ; ; ; Each character is
*or|; .
Examples 1
Input
10 2
**|**|***|
2 5
5 9
Output
2
3
Explanation
Candles occur at indices 2, 5, 9. Substring is |**|, containing plates at 3 and 4. Substring is |***|, containing plates at 6, 7 and 8. Each counted plate is enclosed by candles within its own query.
Examples 2
Input
21 5
***|**|*****|**||**|*
1 17
4 5
14 17
5 11
15 16
Output
9
0
0
0
0
Explanation
Candles are at 3, 6, 12, 15, 16, 19. In , the outermost candles are at 3 and 16, enclosing plates. In there is no candle; has adjacent candles 15 and 16; has only candle 6; has only two adjacent candles. All four counts are zero.