CF1672H.Zigu Zagu
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤l≤r≤n .
Let s=a[l,r] . You are allowed to do the following operation on s :
- Choose two indices x and y such that 1≤x≤y≤∣s∣ . Let t be the substring t=s[x,y] . Then for all 1≤i≤∣t∣−1 , the condition ti=ti+1 has to hold. Note that x=y is always a valid substring.
- Delete the substring s[x,y] from 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 sl,sl+1,…,sr .
输入格式
The first line contains two integers n and q ( 1≤n,q≤2⋅105 ) — the length of the binary string a and the number of queries respectively.
The second line contains a binary string a of length n ( ai∈{0,1} ).
Each of the next q lines contains two integers l and r ( 1≤l≤r≤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.
输入输出样例
输入#1
5 3 11011 2 4 1 5 3 5
输出#1
1 3 2
输入#2
10 3 1001110110 1 10 2 5 5 10
输出#2
4 2 3
说明/提示
In the first test case,
- The substring is 101 , so we can do one operation to make the substring empty.
- The substring is 11011 , so we can do one operation on s[2,4] to make 11 , then use two more operations to make the substring empty.
- The substring is 011 , so we can do one operation on s[1,2] to make 1 , then use one more operation to make the substring empty.