PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000129. Đếm số lần đổi trạng thái (Count State Changes)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm số lần đổi trạng thái (Count State Changes)
Count State Changes
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a string of lowercase English letters, indexed from 1, a state change occurs between adjacent unequal characters. For every interval , count changes whose two characters both lie inside it: positions with and . The string is immutable.
Input
The first line contains , the length and query count.
The second line contains the string of length .
Each of the next lines contains .
Output
Print lines, each containing the number of changes inside its interval.
Subtasks
- Subtask 1 (30 points): ; ; for each query; ; for every .
- Subtask 2 (30 points): ; ; for each query; ; for every .
- Subtask 3 (40 points): ; ; for each query; ; for every .
Example 1
Input
6 2
abbaaa
1 6
2 6
Output
2
1
Explanation
In 1–6, changes occur at pairs (1,2) from a to b and (3,4) from b to a. Only (3,4) lies entirely inside 2–6, giving 1.