This commit is contained in:
Zengtudor 2024-10-06 09:28:39 +08:00
parent 8aeca62d3b
commit aad305dd03

View File

@ -0,0 +1,27 @@
#include <algorithm>
#include <iostream>
#include <string>
using std::cin, std::cout, std::string, std::for_each_n;
typedef unsigned long long ull;
static const size_t MOD {998244353}, MAX_N {300000+5};
static string s;
static size_t left_dp[MAX_N], last_left[MAX_N], unused_left_num, ans;
static ull stk[MAX_N];
int main(){
cin>>s;
for(size_t i {0};i<s.size();i++){
if(s[i]=='('){
stk[unused_left_num++]=i;
}else if(unused_left_num>0){
last_left[i] = stk[--unused_left_num];
cout<<(last_left[i]-1)<<"--\n";
left_dp[i] = (left_dp[last_left[i]-1] + last_left[i]+1) % MOD;
ans = (ans + left_dp[i] * (s.size() - i)) % MOD ;
}
}
cout<<ans<<'\n';
}