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. [Python3] 026 常用模块 calendar

    目录 calendar 1. calendar.calendar(year, w, l, c, m) 2. calendar.prcal(year, w, l, c, m) 3. calendar.m ...

  2. Nginx配置与使用

    一.简单介绍 由俄罗斯程序员IgorSysoev研发,2004年开源公布,特点是:内存cpu占用低,并发能力强,稳定,配置示例,反向代理:互联网企业 70%以上公司都在使用 nginx: 二.安装 1 ...

  3. Virtual DOM和snabbdom.js

    Virtual DOM和snabbdom.js:https://www.jianshu.com/p/1f1ef915e83e

  4. 自己动手实现一个html2canvas

    前言 昨天写了新手引导动画的4种实现方式,里面用到了 html2canvas 于是就顺便了解了一下实现思路. 大概就是 利用 svg 的 foreignObject 标签, 嵌入 dom, 最后再利用 ...

  5. P3964 [TJOI2013]松鼠聚会

    传送门 首先题意就是求一个点到所有其他点的切比雪夫距离和最小 考虑枚举所有点作为答案,那么我们需要快速计算切比雪夫距离和,发现不太好算 根据一些奇怪的套路,我们把坐标系变化,把 $(x,y)$ 变成 ...

  6. Gogs官方帮助文档

    环境要求 数据库(选择以下一项): MySQL:版本 >= 5.7 PostgreSQL MSSQL TiDB(实验性支持,使用 MySQL 协议连接) 或者 什么都不安装 直接使用 SQLit ...

  7. js 判断图片和视频是否加载成功

    图片: 失败: // 方法 1:更换图片地址 $('img').error(function(){ $(this).attr('src', '加载失败.png'); }); // 方法 2:隐藏它 $ ...

  8. 通过SEO可以做什么?

    1.做关键词排名,从而带来大量的客户卖产品和服务.很多大型机械厂家就是这么做的,显然SEO赚取了不少利润.     2.通过SEO带来大量流量,从而投放广告或者跟厂家合作买产品,比如流量站之类.    ...

  9. 在Linux上安装tomcat和JDK

    1.tomcat的安装 a.#cd download(进入download文件夹) b.#wget http://111.23.5.142:82/mirrors.hust.edu.cn/apache/ ...

  10. 从零开始学MySQL(一)

    如果您浏览过许多IT类的招聘职位,那么掌握数据库技能的重要性便不言自明了.因JAVA常常与MySQL所挂钩,因此兴起了写博客记载学习的念头,盼与君共勉.然,在进行MySQL语法的学习之前,我们无不面临 ...