update
This commit is contained in:
parent
560b5bd6aa
commit
b93eef8e0e
@ -1,26 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <ranges>
|
||||
#include <stack>
|
||||
|
||||
|
||||
using std::cin, std::cout, std::string, std::stack;
|
||||
using ull = unsigned long long;
|
||||
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;
|
||||
ull stk[MAX_N], pre[MAX_N], g[MAX_N], ans;
|
||||
size_t tot;
|
||||
ull stk[MAX_N], left_num[MAX_N], g[MAX_N], ans;
|
||||
size_t stk_size;
|
||||
|
||||
int main(){
|
||||
cin>>s;
|
||||
for(const size_t i:range((size_t)0,s.size())){
|
||||
if(s[i]=='('){
|
||||
stk[tot++] = i;
|
||||
}else{
|
||||
pre[i] = stk[tot--];
|
||||
g[i] = ( g[pre[i]-1] + pre[i] ) % MOD;
|
||||
ans = ( ans + g[i] * s.size()-i) % MOD;
|
||||
}
|
||||
int main() {
|
||||
cin >> s;
|
||||
for (const size_t i : range((size_t)0, s.size())) {
|
||||
if (s[i] == '(') {
|
||||
stk[stk_size++] = i + 1;
|
||||
} else if (stk_size > 0) {
|
||||
left_num[i] = stk[--stk_size];
|
||||
g[i] = (g[left_num[i] - 2] + left_num[i]) % MOD;
|
||||
ans = (ans + g[i] * (s.size() - i)) % MOD;
|
||||
}
|
||||
cout<<ans<<'\n';
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
Loading…
Reference in New Issue
Block a user