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

Hint

Source

湖南省第十二届大学生计算机程序设计竞赛

题目大意:给你个平衡的括号串,然后询问a,b两个数字交换后括号串是否依旧平衡

题目思路:如果a,b两个位置的括号是一样的,显然交换了是没有影响的;如果位置在前面的‘)’与位置在后面的‘(’交换后依旧是平衡的括号串;当位置在前面的‘(’与后面的‘)’交换后,用1与-1来遍历一遍字符串,如果中途出现了-1则代表失去平衡无法匹配。

# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(false);
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
///coding................................... const int MAXM=2e5+5;
char a[MAXM]; int main()
{
IOS
#ifdef FLAG
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif /// FLAG
int n,q,q1,q2;
while(cin>>n>>q) {
cin>>a+1;
FOR(i,1,q) {
cin>>q1>>q2;
if(q1>q2)swap(q1,q2);
if(a[q1]==a[q2])puts("Yes");
else if(a[q1]==')')puts("Yes");
else {
int sum=0;
swap(a[q1],a[q2]);
FOR(j,1,n) {
if(a[j]=='(')++sum;
else--sum;
if(sum<0)break;
}
if(sum==0)puts("Yes");
else puts("No");
swap(a[q1],a[q2]);
}
}
}
return 0;
}

湖南省第十二届省赛:Parenthesis的更多相关文章

  1. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  2. 湖南省第十二届大学生计算机程序设计竞赛 G Parenthesis

    1809: Parenthesis Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q ...

  3. 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...

  4. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

  5. 2016年湖南省第十二届大学生计算机程序设计竞赛Problem A 2016 找规律归类

    Problem A: 2016 Time Limit: 5 Sec  Memory Limit: 128 MB Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) ...

  6. 湖南省第十二届大学生计算机程序设计竞赛 F 地铁 多源多汇最短路

    1808: 地铁 Description Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站,用 1,2,…,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i ...

  7. 湖南省第十二届大学生计算机程序设计竞赛 B 有向无环图 拓扑DP

    1804: 有向无环图 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 187  Solved: 80[Submit][Status][Web Board ...

  8. 湖南省第十二届大学生计算机程序设计竞赛 A 2016

    1803: 2016 Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:   1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. In ...

  9. 【模拟】CSU 1807 最长上升子序列~ (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1807 题目大意: 给你一个长度为N(N<=105)的数列,数列中的0可以被其他数 ...

随机推荐

  1. c++嵌入linux指令以查找文件夹

    char buf[256]={0}; char cmd[64] ={0}; FILE *fp=NULL; snprintf(cmd,sizeof(cmd),"ls %s",&quo ...

  2. [Python3] 029 常用模块 timeit

    目录 timeit 直接举例 1. 测量生成列表的时间 2. 测量函数运行时间(一) 3. 测量函数运行时间(二) timeit 直接举例 必要的导入 import timeit 1. 测量生成列表的 ...

  3. Spring Cloud Zuul Filter 和熔断

    转一篇很不错的关于Spring Cloud Zuul 相关用法的文章,基本包含常用的一些场景,另外附上实际项目中的熔断.打印请求日志和登录验证的实例. 原文地址:https://www.cnblogs ...

  4. [转帖].NET Core单文件发布静态编译AOT CoreRT

    .NET Core单文件发布静态编译AOT CoreRT https://www.cnblogs.com/linezero/p/CoreRT.htm .NET Core单文件发布静态编译AOT Cor ...

  5. java--编码规范易漏

    1:命名规范 类名用大驼峰式 参数变量·函数·成员变量·局部变量 小驼峰式 常亮命名全部大些单词用_隔开 抽象类用Abstract开头·异常类用Excetpion结尾·测试类用Test结尾 *POJO ...

  6. C语言---进制

    1. 何为进制 进位机制,逢几进一.数值某一位置上的数在运算时是逢几进一. 生活中的进制:十进制.十二进制(12个月是1年).六十进制(60秒是1分钟) 计算机编程中的进制:二进制.八进制.十六进制. ...

  7. vue-cli 2.* 中导入公共less文件

    在新版的Vue CLI 3中,如何导入公共less文件在文档里已经描述的很清楚了,但是在2.*的版本中,我没有查到相关的办法,网友的办法又相当复杂,于是我推荐给大家一个很简单的办法. 首先,会用到we ...

  8. $APIO~2019$ 游记

    我是鸽子. Upd:我全国倒数第一稳了. Uupd:时间过去好久了,这段时间发生很多事,比如NOIP没了... APIO时候的事也记得不是很清楚了,随便写点颓废资料吧: 如果想吃离酒店最近的一家火锅店 ...

  9. Fliter设置字符编码,解决中文问题

    class EncodingFilter implements FileFilter{ private String encoding; @Override public boolean accept ...

  10. java中的进制转换

    java中的进制转换及转换函数 转自:https://blog.csdn.net/V0218/article/details/74945203 Java的进制转换 进制转换原理 十进制 转 二进制: ...