arrangement of round and square sections is given. You can change the arrangement by playing out the accompanying activities: shift the bearing of a section from opening to shutting as well as the other way around without changing the type of the section: for example you can change '(' to ')' and ')' to '('; you can change '[' to ']' and ']' to

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please do in c++ only. Correct answer only else downvoted.

 

 

arrangement of round and square sections is given. You can change the arrangement by playing out the accompanying activities: shift the bearing of a section from opening to shutting as well as the other way around without changing the type of the section: for example you can change '(' to ')' and ')' to '('; you can change '[' to ']' and ']' to '['. The activity costs 0 burles. 

change any square section to adjust section having a similar bearing: for example you can change '[' to '(' however not from '(' to '['; likewise, you can change ']' to ')' yet not from ')' to ']'. The activity costs 1 burle. The tasks can be acted in any request quite a few times. You are given a string s of the length n and q questions of the sort "l r" where 1≤l<r≤n. For each substring s[l… r], track down the base expense to pay to make it a right section grouping. It is ensured that the substring s[l… r] has an even length. 

The inquiries should be handled freely, for example the progressions made in the string for the response to an inquiry I don't influence the inquiries j (j>i). As such, for each question, the substring s[l… r] is given from the at first given string s. 

Input :The principal line contains one integer t (1≤t≤100) — the number of experiments. Then, at that point, t experiments follow. For each experiment, the main line contains a non-void string s containing just round ('(', ')') and square ('[', ']') sections. The length of the string doesn't surpass 106. The string contains somewhere around 2 characters. 

The subsequent line contains one integer q (1≤q≤2⋅105) — the number of questions. 

Then, at that point, q lines follow, every one of them contains two integers l and r (1≤l<r≤n where n is the length of s). It is ensured that the substring s[l… r] has even length. It is ensured that the amount of the lengths of all strings given in all experiments doesn't surpass 106. The amount of all q given in all experiments doesn't surpass 2⋅105. 

Output :For each experiment output in a different line for each question one integer x (x≥0) — the base expense to pay to make the given substring a right section succession.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY