CF BUDDY
← Problems·

1902D · Robot Queries

1900 · binary search, data structures, dp

Problem: 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,y1)(x, y - 1);
  • L — move from point (x,y)(x, y) to (x1,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 s1s2s3sl1srsr1sr2slsr+1sr+2sns_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).

Input Format: The first line contains two integers nn and qq (1n,q21051 \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 (nxi,yin-n \le x_i, y_i \le n; 1lrn1 \le l \le r \le n) describing the ii-th query.

Output Format: 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.

Note: 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:

Sample Cases

Case 1

Input

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

Output

YES
YES
NO

Case 2

Input

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

Output

YES
NO

Case 3

Input

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

Output

YES
YES
YES
NO
YES
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback