CF1902D.Robot Queries

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is an infinite 22-dimensional grid. Initially, a robot stands in the point (0,0)(0, 0). The robot can execute four commands:

  • U — move from point (x,y)(x, y) to (x,y+1)(x, y + 1);
  • D — move from point (x,y)(x, y) to (x,y−1)(x, y - 1);
  • L — move from point (x,y)(x, y) to (x−1,y)(x - 1, y);
  • R — move from point (x,y)(x, y) to (x+1,y)(x + 1, y).

You are given a sequence of commands ss of length nn. Your task is to answer qq independent queries: given four integers xx, yy, ll and rr; determine whether the robot visits the point (x,y)(x, y), while executing a sequence ss, but the substring from ll to rr is reversed (i. e. the robot performs commands in order s1s2s3…sl−1srsr−1sr−2…slsr+1sr+2…sns_1 s_2 s_3 \dots s_{l-1} s_r s_{r-1} s_{r-2} \dots s_l s_{r+1} s_{r+2} \dots s_n).

存在一个无限大的二维网格。初始时,机器人位于点 (0,0)(0, 0)。机器人可以执行以下四种指令:

  • U — 从点 (x,y)(x, y) 移动到 (x,y+1)(x, y + 1);
  • D — 从点 (x,y)(x, y) 移动到 (x,y−1)(x, y - 1);
  • L — 从点 (x,y)(x, y) 移动到 (x−1,y)(x - 1, y);
  • R — 从点 (x,y)(x, y) 移动到 (x+1,y)(x + 1, y)。

给定一个长度为 nn 的指令序列 ss。你需要回答 qq 个相互独立的询问:每次询问给出四个整数 xx、yy、ll 和 rr;判断机器人在执行序列 ss 的过程中(但将子串 s[l..r]s[l..r] 反转)是否会访问点 (x,y)(x, y)(即机器人执行的指令序列为 s1s2s3…sl−1srsr−1sr−2…slsr+1sr+2…sns_1 s_2 s_3 \dots s_{l-1} s_r s_{r-1} s_{r-2} \dots s_l s_{r+1} s_{r+2} \dots s_n)。

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5) — the length of the command sequence and the number of queries, respectively.

The second line contains a string ss of length nn, consisting of characters U, D, L and/or R.

Then qq lines follow, the ii-th of them contains four integers xix_i, yiy_i, lil_i and rir_i (−n≤xi,yi≤n-n \le x_i, y_i \le n; 1≤l≤r≤n1 \le l \le r \le n) describing the ii-th query.

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5),分别表示指令序列的长度和查询次数。

第二行包含一个长度为 nn 的字符串 ss,由字符 U、D、L 和/或 R 组成。

接下来是 qq 行,其中第 ii 行包含四个整数 xix_i、yiy_i、lil_i 和 rir_i(−n≤xi,yi≤n-n \le x_i, y_i \le n;1≤l≤r≤n1 \le l \le r \le n),描述第 ii 个查询。

输出格式

For each query, print YES if the robot visits the point (x,y)(x, y), while executing a sequence ss, but the substring from ll to rr is reversed; otherwise print NO.

对于每个查询,如果机器人在执行序列 ss 时访问了点 (x,y)(x, y),但子串 s[l..r]s[l..r] 被反转,则输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    8 3
    RDLLUURU
    -1 2 1 7
    0 0 3 4
    0 1 7 8

    输出#1

    YES
    YES
    NO
  • 输入#2

    4 2
    RLDU
    0 0 2 2
    -1 -1 2 3

    输出#2

    YES
    NO
  • 输入#3

    10 6
    DLUDLRULLD
    -1 0 1 10
    -1 -2 2 5
    -4 -2 6 10
    -1 0 3 9
    0 1 4 7
    -3 -1 5 8

    输出#3

    YES
    YES
    YES
    NO
    YES
    YES

说明/提示

In the first query of the first sample, the path of the robot looks as follows:

In the second query of the first sample, the path of the robot looks as follows:

In the third query of the first sample, the path of the robot looks as follows:

在第一个样例的第一个查询中,机器人的路径如下所示:

在第一个样例的第二个查询中,机器人的路径如下所示:

在第一个样例的第三个查询中,机器人的路径如下所示:

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

首页