#P15167. [SWERC 2022] Controllers

[SWERC 2022] Controllers

题目描述

You are at your grandparents' house and you are playing an old video game on a strange console. Your controller has only two buttons and each button has a number written on it.

Initially, your score is 0 0 . The game is composed of n n rounds. For each 1in 1\le i\le n , the i i -th round works as follows.

On the screen, a symbol si s_i appears, which is either + \texttt{+} (plus) or - \texttt{-} (minus). Then you must press one of the two buttons on the controller once. Suppose you press a button with the number x x written on it: your score will increase by x x if the symbol was + \texttt{+} and will decrease by x x if the symbol was - \texttt{-} . After you press the button, the round ends.

After you have played all n n rounds, you win if your score is 0 0 .

Over the years, your grandparents bought many different controllers, so you have q q of them. The two buttons on the j j -th controller have the numbers aj a_j and bj b_j written on them. For each controller, you must compute whether you can win the game playing with that controller.

输入格式

The first line contains a single integer n n ( 1n2105 1 \le n \le 2\cdot 10^5 ) — the number of rounds.

The second line contains a string s s of length n n — where si s_i is the symbol that will appear on the screen in the i i -th round. It is guaranteed that s s contains only the characters + \texttt{+} and - \texttt{-} .

The third line contains an integer q q ( 1q105 1 \le q \le 10^5 ) — the number of controllers.

The following q q lines contain two integers aj a_j and bj b_j each ( 1aj,bj109 1 \le a_j, b_j \le 10^9 ) — the numbers on the buttons of controller j j .

输出格式

Output q q lines. On line j j print YES \texttt{YES} if the game is winnable using controller j j , otherwise print NO \texttt{NO} .

8
+-+---+-
5
2 1
10 3
7 9
10 10
5 3
YES
NO
NO
NO
YES
6
+-++--
2
9 7
1 1
YES
YES
20
+-----+--+--------+-
2
1000000000 99999997
250000000 1000000000
NO
YES

提示

In the first sample, one possible way to get score 0 0 using the first controller is by pressing the button with numnber 1 1 in rounds 1 1 , 2 2 , 4 4 , 5 5 , 6 6 and 8 8 , and pressing the button with number 2 2 in rounds 3 3 and 7 7 . It is possible to show that there is no way to get a score of 0 0 using the second controller.