http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 给定一串平衡的序列,要求交换两个位置之后,问其是否还平衡. 首先要注意到交换的是两个位置,这两个位置没有大小之分,所以要判断是否swap他们,保持相对大小 然后如果我们把'('当成是1,把')'当成是-1,那么序列平衡,那么前缀和就是0了. 然后考虑下交换的时候,如果就交换相同的字符,那么肯定是Yes了,如果是')' 和 '(',那么也是Yes 因为本来序列就是平衡的,现在这样交换,只不过…
Parenthesis Problem 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 affec…
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5172 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=567&pid=1003 题解: 线段树+前缀和 一个区间要满足1到n的一个排列,要同时满足两点,一是它的和是n*(n+1)/2,这个可以用前缀和直接求:二是它每个元素不能重复. 区间内每个元素都不能重复: 记录第i个元素的左边一个离…
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1809 Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are ind…
1809: Parenthesis Submit Page     Summary    Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 1500     Solved: 398 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P re…
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<=105)个询问,每次交换x,y位置上的括号后这个序列是否还合法,询问之间不影响. 题目思路: [贪心] 首先可以肯定,交换相同的括号是不会有影响的.把后面的'('和前面的')'交换也不会有影响.所以只用考虑把前面'('和后面的')'交换 而这时要满足x,y之间的所有位置i不会存在,1~i个括号中左括号数少于右…
1809: Parenthesis Submit 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…
题目见此 分析,把'('当成1, ')'当成-1, 计算前缀和sum. 记交换括号左边的序号为u, 右边为v,讨论左右括号: 1.s[u] == '(' && s[v] == ')' 那么[u, v - 1]的前缀和会全部-2 2.s[u] == '(' && s[v] == '(' 显然 3.s[u] == ')' && s[v] == '(' 那么[u, v - 1]的前缀和会全部+2 4.s[u] == ')' && s[v] == '…
http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护每个点的次数... 然后就ok了.. 第二种做法:用前缀和来维护即可... 线段树: #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <ios…
https://vijos.org/p/1750 是不是我想复杂了.... 自己yy了个二维线段树,然后愉快的敲打. 但是wa了两法.......sad 原因是在处理第二维的更新出现了个小问题,sad. void pushup1(int x) { for1(i, 1, mm<<2) mn[x][i]=min(mn[lc][i], mn[rc][i]); } 这里注意是mm*4...我该好好想想了..这是在dbg的时候找出来的问题.sad. 我觉得很奇怪,线段树的底层节点一共就mm个,那么整棵树…