This commit is contained in:
Zengtudor 2024-10-05 19:08:02 +08:00
parent 560b5bd6aa
commit b93eef8e0e

View File

@ -1,26 +1,27 @@
#include <iostream> #include <iostream>
#include <stack>
#include <ranges> #include <ranges>
#include <stack>
using std::cin, std::cout, std::string, std::stack; using std::cin, std::cout, std::string, std::stack;
using ull = unsigned long long; using ull = unsigned long long;
constexpr auto range = std::ranges::views::iota; constexpr auto range = std::ranges::views::iota;
constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353}; constexpr size_t MAX_N{(size_t)3e5 + 5}, MOD{998244353};
string s; string s;
ull stk[MAX_N], pre[MAX_N], g[MAX_N], ans; ull stk[MAX_N], left_num[MAX_N], g[MAX_N], ans;
size_t tot; size_t stk_size;
int main(){ int main() {
cin>>s; cin >> s;
for(const size_t i:range((size_t)0,s.size())){ for (const size_t i : range((size_t)0, s.size())) {
if(s[i]=='('){ if (s[i] == '(') {
stk[tot++] = i; stk[stk_size++] = i + 1;
}else{ } else if (stk_size > 0) {
pre[i] = stk[tot--]; left_num[i] = stk[--stk_size];
g[i] = ( g[pre[i]-1] + pre[i] ) % MOD; g[i] = (g[left_num[i] - 2] + left_num[i]) % MOD;
ans = ( ans + g[i] * s.size()-i) % MOD; ans = (ans + g[i] * (s.size() - i)) % MOD;
}
} }
cout<<ans<<'\n'; }
cout << ans << '\n';
} }