Codeforces Global Round 20 |
---|
Finished |
You have a binary string $$$a$$$ of length $$$n$$$ consisting only of digits $$$0$$$ and $$$1$$$.
You are given $$$q$$$ queries. In the $$$i$$$-th query, you are given two indices $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$.
Let $$$s=a[l,r]$$$. You are allowed to do the following operation on $$$s$$$:
For each of the $$$q$$$ queries, find the minimum number of operations needed to make $$$s$$$ an empty string.
Note that for a string $$$s$$$, $$$s[l,r]$$$ denotes the subsegment $$$s_l,s_{l+1},\ldots,s_r$$$.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10 ^ 5$$$) — the length of the binary string $$$a$$$ and the number of queries respectively.
The second line contains a binary string $$$a$$$ of length $$$n$$$ ($$$a_i \in \{0, 1\}$$$).
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) — representing the substring of each query.
Print $$$q$$$ lines, the $$$i$$$-th line representing the minimum number of operations needed for the $$$i$$$-th query.
5 3 11011 2 4 1 5 3 5
1 3 2
10 3 1001110110 1 10 2 5 5 10
4 2 3
In the first test case,
Name |
---|