Codeforces 1239B. The World Is Just a Programming Task (Hard Version)
传送门这一题好妙啊首先把括号序列转化成平面直角坐标系$xOy$上的折线,初始时折线从坐标系原点$(0,0)$出发如果第$i$个位置是'('那么折线就往上走一步($y+1$),否则往下走一步($y-1$)这条折线有很多有用的性质$1.$如果某个时刻折线的纵坐标为负数了,那么说明这个括号序列一定是不合法的证明也挺好理解的,变成负数说明没有足够的'('和')'匹配了,显然不合法$2.$如果最终位置$n$