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. 2019JAVA第六次实验报告

    Java实验报告 班级 计科二班 学号 20188442 姓名 吴怡君 完成时间 2019.10.18 评分等级 实验四 类的继承 实验目的 理解异常的基本概念: 掌握异常处理方法及熟悉常见异常的捕获 ...

  2. mybatis+mysql 返回主键

    需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值. 方法:在mapper中指定keyProperty属性,示例如下: <insert id="i ...

  3. MongoDB数据库的操作

    一.操作MongoDB数据库 1.创建数据库 语法:ues 注意:如果数据库不存在则再创建数据库,否则切换到指定的 数据库!如果刚刚创建的数据不在列表中,如果需要显示这个数 据库,那么需要在刚刚创建的 ...

  4. Java学习:identityHashCode和hashCode方法

    System类提供了一个identityHashCode(Object x)方法,这个方法返回的是指定对象的精确hashCode值,也就是根据该对象的地址计算得到的hashCode值. 当某个类的ha ...

  5. eclipse控制台输出太多被顶掉问题

    控制台空白处右键 属性

  6. 利用ios safari浏览器生成桌面快捷方式并唤醒app的示例代码

    html 内容: //通过a链接唤醒app  <a href="app约定好的scheme" id="qbt" style="display:n ...

  7. Thymeleaf后台传值读取

    /** * 测试用Controller *  * @author  * @date 2019-08-15 */@Controller@RequestMapping("/danyu/test& ...

  8. 十二、LaTex中数学公式多行排版

  9. Linux设置静态IP后出现的几种问题

    一.设置静态IP后无法重启网卡 如下图所示 原因分析:control process exited with error code.控制进程存在错误代码. 解决方案:可以检查网卡配置文件是否修改错误. ...

  10. 4、MySQL 申明变量给查询数据编号

    摘自: https://www.cnblogs.com/qixuejia/archive/2010/12/21/1913203.html https://blog.csdn.net/arbben/ar ...