CF1776L.Controllers

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 00. The game is composed of nn rounds. For each 1≤i≤n1\le i\le n, the ii-th round works as follows.

On the screen, a symbol sis_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 xx written on it: your score will increase by xx if the symbol was +\texttt{+} and will decrease by xx if the symbol was -\texttt{-}. After you press the button, the round ends.

After you have played all nn rounds, you win if your score is 00.

Over the years, your grandparents bought many different controllers, so you have qq of them. The two buttons on the jj-th controller have the numbers aja_j and bjb_j written on them. For each controller, you must compute whether you can win the game playing with that controller.

你正在祖父母家,玩一款老式电子游戏,而游戏机的控制器十分奇特:它只有两个按钮,每个按钮上都标有一个数字。

初始时,你的得分为 00。游戏共包含 nn 轮。对每个 1≤i≤n1\le i\le n,第 ii 轮的规则如下:

屏幕上会显示一个符号 sis_i,该符号要么是 +\texttt{+}(加号),要么是 -\texttt{-}(减号)。接着,你必须按下控制器上的两个按钮之一,且仅能按一次。假设你按下的按钮上标有数字 xx:若屏幕上显示的是 +\texttt{+},则你的得分增加 xx;若显示的是 -\texttt{-},则你的得分减少 xx。按下按钮后,本轮结束。

当你完成全部 nn 轮后,若最终得分为 00,则获胜。

多年来,祖父母购买了许多不同的控制器,因此你一共有 qq 个控制器。第 jj 个控制器的两个按钮上分别标有数字 aja_j 和 bjb_j。对每个控制器,你需要判断:使用该控制器是否能够赢得游戏。

输入格式

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

The second line contains a string ss of length nn — where sis_i is the symbol that will appear on the screen in the ii-th round. It is guaranteed that ss contains only the characters +\texttt{+} and -\texttt{-}.

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

The following qq lines contain two integers aja_j and bjb_j each (1≤aj,bj≤1091 \le a_j, b_j \le 10^9) — the numbers on the buttons of controller jj.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot 10^5)—— 表示回合数。

第二行包含一个长度为 nn 的字符串 ss —— 其中 sis_i 表示第 ii 回合屏幕上将显示的符号。保证字符串 ss 仅由字符 +\texttt{+} 和 -\texttt{-} 组成。

第三行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 表示控制器的数量。

接下来的 qq 行每行包含两个整数 aja_j 和 bjb_j(1≤aj,bj≤1091 \le a_j, b_j \le 10^9)—— 分别表示第 jj 个控制器上两个按钮的数字。

输出格式

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

输出 qq 行。在第 jj 行,如果使用控制器 jj 可以赢得游戏,则输出 YES\texttt{YES},否则输出 NO\texttt{NO}。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    NO
    NO
    YES
  • 输入#2

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

    输出#2

    YES
    YES
  • 输入#3

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

    输出#3

    NO
    YES

说明/提示

In the first sample, one possible way to get score 00 using the first controller is by pressing the button with numnber 11 in rounds 11, 22, 44, 55, 66 and 88, and pressing the button with number 22 in rounds 33 and 77. It is possible to show that there is no way to get a score of 00 using the second controller.

在第一个样例中,使用第一个控制器得到分数 00 的一种可能方式是:在第 11、22、44、55、66 和 88 轮按下编号为 11 的按钮,在第 33 和 77 轮按下编号为 22 的按钮。可以证明,使用第二个控制器无法得到分数 00。

输入解题思路,AI测评打分。不知道怎么写?

首页