PARENTHESES
시간 제한0.3초메모리 제한1024 MB
여는 괄호와 닫는 괄호의 수가 같은 부분 문자열 Q개에 대해, 정규 괄호열로 만들기 위한 최소 교환 횟수를 구한다.
문제
Who doesn't love parentheses?
Sashka stumbled upon a bracket sequence of parentheses, from which are opening parentheses and are closing parentheses. She defines the bracket sequence's clumsiness as the minimum number of required swaps of elements to turn it into a regular parentheses sequence. The regular parentheses sequences follow these rules:
- The empty sequence is a regular parentheses sequence.
- is a regular non-empty parentheses sequence iff two regular sequences and exist such that , where denotes the operation concatenation of two sequences.
Sashka wants to know the clumsiness for such sequences , where the -th of them consists of all the elements in from position to inclusive. It is guaranteed that every sequence consists of equal number of opening and closing parentheses. Write a program parentheses, which answers the questions.
입력
The first line of the standard input contains the three integers , and , which describe the number of opening parentheses in the sequence, the number of questions and the number of the subtask that the test is from. The second line contains parentheses, respectively. The last lines of the standard input contain the integers and , which describe the positions for the -th question.
출력
On the standard output print one number on each line, the -th number being the minimum number of required swaps to turn into a regular parentheses sequence.
제한
- All questions are different from one another.