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
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.
Step by step
Solved in 4 steps with 1 images