Parenthesis

/*

Problem G: Parenthesis
Time Limit: 5 Sec Memory Limit: 128 MB
Submit: 12 Solved: 4
[Submit][Status][Web Board]
Description

Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions.

The i-th question is whether P remains balanced after pai and pbi swapped. Note that questions are individual so that they have no affect on others.

Parenthesis sequence S is balanced if and only if:

  1. S is empty;

  2. or there exists balanced parenthesis sequence A,B such that S=AB;

  3. or there exists balanced parenthesis sequence S’ such that S=(S’).

Input

The input contains at most 30 sets. For each set:

The first line contains two integers n,q (2≤n≤105,1≤q≤105).

The second line contains n characters p1 p2…pn.

The i-th of the last q lines contains 2 integers ai,bi (1≤ai,bi≤n,ai≠bi).

Output

For each question, output “Yes” if P remains balanced, or “No” otherwise.

Sample Input
4 2
(())
1 3
2 3
2 1
()
1 2

Sample Output
No
Yes
No
*/

/*
题意:给一个合法括号字符串,询问调换两个字符,字符串是否仍合法? (如果括号串从左到右能镶嵌匹配就合法,其实就”合法)(合法”这
种情况不行啦),空串也合法;
思路:规律题,只有”()”这种情况需要讨论.如果询问区间内没有某个位置f(=前的左括号数减右括号数)小于2,则yes,否则no.比赛时找到规律,
却跪在线段树上了…其实可以对每个前缀区间统计f,然后前缀区间相减,如果结果大于零就no~~比赛完才立马意识到Orz…
*/

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=1e5+100;
int n,q;
int sum[maxn];
char str[maxn];

int main()
{
    while (scanf("%d%d",&n,&q)==2)
    {
        scanf("%s",str+1);
        memset(sum,0,sizeof sum);
        int num=0,now=0;//now表示当前位置f,num表示此前出现f<2的次数
        for (int i=1; i<=n; i++){
            if (str[i]=='('){
                now++;
            }
            else {
                now--;
            }
            if (now<2){
                num++;
            }
            sum[i]=num;
        }
        for (int i=1;i<=q;i++){
            int a,b;
            scanf("%d%d",&a,&b);
            if (a>b) swap(a,b);//这应该可以坑下爹
            if (str[a]=='('&&str[b]==')'){//只需考虑();
                if(sum[a-1]==sum[b-1]){//区间前后sum值不变,说明区间内没有f<2;
                    printf("Yes\n");
                }
                else{
                    printf("No\n");
                }
            }
            else {
                printf("Yes\n");
            }
        }
    }
    return 0;
}
"missing right parenthesis"是Oracle数据库错误消息之一,表示在查询语句或存储过程中缺少右括号。这可能是由于在语句中的某个地方忘记了闭合括号导致的语法错误。这种错误通常由于括号未匹配或嵌套不正确引起。 引用中提到了一些与Oracle数据库相关的错误消息,包括"missing right parenthesis"。该错误消息在语法错误时会出现,比如在查询语句或存储过程中缺少右括号。 引用中的示例代码提示了一个可能导致"missing right parenthesis"错误的情况。在将系统时间格式转换并与数据库字段进行比较时,如果忘记闭合括号,就会出现这个错误。 要解决这个问题,您需要仔细检查查询语句或存储过程中的括号使用情况,确保每个左括号都有一个相应的右括号进行闭合。检查您的代码中的每个括号,确保它们正确匹配并嵌套正确。另外,还要确保您在使用括号时遵循正确的语法规则。 如果您仍然遇到困难,可以将相关代码片段提供给数据库管理员或开发人员,以便他们可以更详细地分析并解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [SQL21日自学通](https://download.csdn.net/download/mao_zh/8277811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [关于ORA-00907: missing right parenthesis问题整理](https://blog.csdn.net/weixin_31960565/article/details/116466386)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值