CSU 1809 Parenthesis 思维+线段树】的更多相关文章

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…
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…
Buy Tickets POJ - 2828 思维+线段树 题意 是说有n个人买票,但是呢这n个人都会去插队,问最后的队列是什么情况.插队的输入是两个数,第一个是前面有多少人,第二个是这个人的编号,最后输出编号就好了. 解题思路 这个题要倒着处理,因为最后一个人插队完成后,别人就不能影响他了.他前面有n个人,那么他就是n+1号位置上,这样来的话,我们只需要知道那个位置,他前面有n个人就行.默认每个位置都没有人. 详细看代码. 代码实现 #include<cstdio> #include<…
题目链接: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…
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 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 ar…
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<=105)个询问,每次交换x,y位置上的括号后这个序列是否还合法,询问之间不影响. 题目思路: [贪心] 首先可以肯定,交换相同的括号是不会有影响的.把后面的'('和前面的')'交换也不会有影响.所以只用考虑把前面'('和后面的')'交换 而这时要满足x,y之间的所有位置i不会存在,1~i个括号中左括号数少于右…
Rikka with Parenthesis II 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Correct parenthe…
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…
前言 听说是线段树离线查询?? 做题做着做着慢慢对离线操作有点感觉了,不过也还没参透,等再做些题目再来讨论离线.在线操作. 这题赛后看代码发现有人用的树状数组,$tql$.当然能用树状数组写的线段树也能写,最重要的还是思维上面. 我当时是怎么想来着.一看异或和前缀和不是很像么,我先把数组中所有数字连续异或并存起来,就像处理前缀和一样的.之后对于每组查询,我只要找到区间中相等的数就可以了,然后再取这些数中相隔最近的距离输出即可.想法很好,但是现实很骨感,这样一来每个区间都这样处理不就超时了么,遂放…
题目见此 分析,把'('当成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] == '…