QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#10299. Metropolis

Statistics

对于一个由左括号 ( 和右括号 ) 构成的字符串,我们称它是匹配括号串,当且仅当其中左右括号数量相等,且存在一种将左右括号一一匹配的方案,使得任何匹配中左括号在右括号前面,且任何两对匹配对应的区间要么不相交,要么有包含关系。

对于两个匹配括号串 $X,Y$,我们称 $X$ 能生成 $Y$ 当且仅当可以从 $X$ 中删除若干对(可以为 $0$ 对)匹配的括号对得到 $Y$。

给定长度为 $n$ 的匹配括号串 $A$ 和长度为 $m$ 的匹配括号串 $B$,有 $q$ 次询问,每次询问给定 $l_1,r_1,l_2,r_2$,求 $A[l_1,r_1]$ 能否生成 $B[l_2,r_2]$,保证这两个子串都是匹配括号串。

输入格式

从标准输入读入数据。

第一行:三个整数 $n,m,q$。

第二行:一个长度为 $n$ 的字符串 $A$。

第三行:一个长度为 $m$ 的字符串 $B$。

接下来 $q$ 行:每行四个整数 $l_1,r_1,l_2,r_2$,描述一个询问。

输出格式

输出到标准输出。

输出共 $q$ 行:若答案为肯定,输出 YES;若答案为否定,输出 NO

样例

输入

8 8 8
(()())()
(())()()
1 6 1 4
1 6 1 6
1 6 5 8
2 5 1 4
2 5 5 8
7 8 7 8
1 8 1 8
1 8 1 6

输出

YES
NO
YES
NO
YES
YES
NO
YES

子任务

对于全部数据:$1\leq n,m,q\leq 12000,\ 1\leq l_1< r_1\leq n,\ 1\leq l_2< r_2\leq m$,保证 $A,B$ 以及每次询问的子串都是匹配括号串。

$\text{Subtask 1}(15\%)$:$n,m\leq 30$。

$\text{Subtask 2}(20\%)$:$n,m\leq 100$。

$\text{Subtask 3}(15\%)$:$n,m\leq 600$。

$\text{Subtask 4}(20\%)$:$n,m\leq 4000$。

$\text{Subtask 5}(30\%)$:无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.