Skip to content
neoideasblog

neoideasblog

  • Home
    • Privacy Policy
    • About Us
    • Contact Us
    • Terms
  • Trivia
  • Results
  • Admit Cards
  • Sitemaps
  • Toggle search form

Zigu Zagu solution codeforces

Posted on April 23, 2022 By Admin No Comments on Zigu Zagu solution codeforces

Zigu Zagu solution codeforces

 

You have a binary string aa of length nn consisting only of digits  and 11.

You are given qq queries. In the ii-th query, you are given two indices ll and rr such that 1≤l≤r≤n1≤l≤r≤n.

Let s=a[l,r]s=a[l,r]. You are allowed to do the following operation on ss:

  1. Choose two indices xx and yy such that 1≤x≤y≤|s|1≤x≤y≤|s|. Let tt be the substring t=s[x,y]t=s[x,y]. Then for all 1≤i≤|t|−11≤i≤|t|−1, the condition ti≠ti+1ti≠ti+1 has to hold. Note that x=yx=y is always a valid substring.
  2. Delete the substring s[x,y]s[x,y] from ss.
ALSO READ:-   [Ques] Of the following Scrabble letters, which letter is worth the most points?

For each of the qq queries, find the minimum number of operations needed to make ss an empty string.

Note that for a string ss, s[l,r]s[l,r] denotes the subsegment sl,sl+1,…,srsl,sl+1,…,sr.

Input

The first line contains two integers nn and qq (1≤n,q≤2⋅1051≤n,q≤2⋅105)  — the length of the binary string aa and the number of queries respectively.

The second line contains a binary string aa of length nn (ai∈{,1}ai∈{0,1}).

ALSO READ:-   [Question] What was the Louvre originally built as in 1190?

Each of the next qq lines contains two integers ll and rr (1≤l≤r≤n1≤l≤r≤n)  — representing the substring of each query.

Output

Print qq lines, the ii-th line representing the minimum number of operations needed for the ii-th query.

Examples
input

Copy
5 3
11011
2 4
1 5
3 5
output

Copy
1
3
2
input

Copy
10 3
1001110110
1 10
2 5
5 10
output

Copy
4
2
3
Note

In the first test case,

  1. The substring is 101101, so we can do one operation to make the substring empty.
  2. The substring is 1101111011, so we can do one operation on s[2,4]s[2,4] to make 1111, then use two more operations to make the substring empty.

    ANSWER

    “Click Here“

Admin

I am the Founder and the creator of the blog neoideasblog.com where we share latest trivia questions and answers on a daily basis.

ALSO READ:-   [Question] 5. If you were speaking directly to a person older than you or a teacher, which pronoun should you use in addressing that person?
Trivia

Post navigation

Previous Post: Cross Xor solution codeforces
Next Post: PermutationForces solution codeforces

Related Posts

[Answer] 4. What was the name of the theatre that President Lincoln was shot in? Trivia
[Question] Instead of the Easter Bunny, which country has an “Easter Bilby”? Trivia
[Question] Which U.S. state is home to the largest mushroom farm in the world? Trivia
[Question] What President received the first presidential email? Trivia
[Question] Where is this lighthouse that hasn’t been lit since 1919? Trivia
[Question] Sender With Largest Word Count solution leetcode Trivia

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • July 2022
  • June 2022
  • May 2022
  • April 2022

Categories

  • Admit Cards
  • Results
  • Trivia

Disclaimer

Disclaimer: Our website name Neoideasblog.com. we are just a news portal that covers various updates and stories.

Copyright © 2022 neoideasblog.

Powered by PressBook Grid Blogs theme