QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#9925. LR 字符串

统计

Gamenjoy 有一个只由 “L” 和 “R” 组成的喜爱字符串。 然而,Gamenjoy 淘气的弟弟 Gamanyong 修改了这个字符串。形式化地,他进行了若干次(可能为零次)操作,每次操作可以是以下两种之一:

  • 选择字符串中一个不是第一个字符的 “L”,并删除其左侧的字符。
  • 选择字符串中一个不是最后一个字符的 “R”,并删除其右侧的字符。

当 Gamenjoy 回家时,他已经无法分辨哪一个是他的喜爱字符串了。幸运的是,他记得弟弟修改前字符串的样子。Gamenjoy 在家里找到了 $q$ 个字符串,并询问他们的父亲 Oibuth,每个字符串是否可能是他原来的喜爱字符串。现在 Oibuth 向你求助。请帮他回答 Gamenjoy 的问题。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。 对于每个测试用例,第一行包含一个字符串 $s$ ($1 \le |s| \le 5 \cdot 10^5$),仅由 “L” 和 “R” 组成,表示原始字符串。 第二行包含一个整数 $q$ ($1 \le q \le 5 \cdot 10^5$),表示 Gamenjoy 家中字符串的数量。 接下来的 $q$ 行中,第 $i$ 行包含一个字符串 $t_i$ ($1 \le |t_i| \le |s|$),仅由 “L” 和 “R” 组成,表示 Gamenjoy 家中的一个字符串。 保证所有测试用例中 $|s|$ 的总和、 $q$ 的总和以及 $|t_i|$ 的总和均不超过 $10^6$。

输出格式

对于 Gamenjoy 家中的每个字符串,如果该字符串可能是他的喜爱字符串,则输出 “YES”。否则,输出 “NO”。

样例

输入 1

2
RRLLRRLL
4
LLLLL
LLR
LRLR
R
RLLLLLL
3
LLLLL
RL
RRL

输出 1

NO
YES
NO
YES
YES
YES
NO

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.