QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 2048 MB 満点: 100

#5652. 控制器

統計

你在祖父母家玩一台奇怪游戏机上的老游戏。你的手柄只有两个按钮,每个按钮上都写有一个数字。

初始分数为 0。游戏由 $n$ 轮组成。对于每一轮 $1 \le i \le n$,游戏过程如下:

屏幕上会出现一个符号 $s_i$,它是 $+$(加号)或 $-$(减号)。然后你必须按一次手柄上的两个按钮之一。假设你按下了写有数字 $x$ 的按钮:如果符号是 $+$,你的分数将增加 $x$;如果符号是 $-$,你的分数将减少 $x$。按下按钮后,该轮结束。

在玩完所有 $n$ 轮后,如果你的分数为 0,则获胜。

多年来,你的祖父母买了很多不同的手柄,所以你现在有 $q$ 个手柄。第 $j$ 个手柄的两个按钮上分别写着数字 $a_j$ 和 $b_j$。对于每个手柄,你必须计算使用该手柄是否能赢得游戏。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示轮数。

第二行包含一个长度为 $n$ 的字符串 $s$,其中 $s_i$ 是第 $i$ 轮屏幕上出现的符号。保证 $s$ 仅包含字符 $+$ 和 $-$。

第三行包含一个整数 $q$ ($1 \le q \le 10^5$),表示手柄的数量。

接下来的 $q$ 行,每行包含两个整数 $a_j$ 和 $b_j$ ($1 \le a_j, b_j \le 10^9$),表示第 $j$ 个手柄上两个按钮的数字。

输出格式

输出 $q$ 行。对于第 $j$ 行,如果使用第 $j$ 个手柄可以赢得游戏,则输出 YES,否则输出 NO

样例

样例输入 1

8
+-+---+-
5
2 1
10 3
7 9
10 10
5 3

样例输出 1

YES
NO
NO
NO
YES

说明

样例 1 的解释: 使用第一个手柄获得 0 分的一种可能方法是:在第 1、2、4、5、6 和 8 轮按下数字 1 的按钮,在第 3 和 7 轮按下数字 2 的按钮。可以证明,使用第二个手柄无法获得 0 分。

样例输入 2

6
+-++--
2
9 7
1 1

样例输出 2

YES
YES

样例输入 3

20
+-----+--+--------+-
2
1000000000 99999997
250000000 1000000000

样例输出 3

NO
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.