From 2ab924b825e1d7a2c9e9d27bce593ca5508288bd Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 6 Oct 2024 23:38:08 +0800 Subject: [PATCH] update --- src/U206625/U206625_video.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/U206625/U206625_video.cpp diff --git a/src/U206625/U206625_video.cpp b/src/U206625/U206625_video.cpp new file mode 100644 index 0000000..a968100 --- /dev/null +++ b/src/U206625/U206625_video.cpp @@ -0,0 +1,24 @@ +#include +#include + +using std::cin, std::cout, std::string; +using ull = unsigned long long; + +constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353}; +string s; +ull left_ok[MAX_N], stk[MAX_N], stk_size, left_index[MAX_N], ans; + +int main(){ + cin>>s; + + for(size_t i {1};i<=s.size();i++){ + if(s[i-1]=='('){ + stk[stk_size++] = i; + }else if(stk_size>0){ + left_index[i] = stk[--stk_size]; + left_ok[i] = (left_ok[left_index[i]-1] + left_index[i]) % MOD; + ans = ( ans + left_ok[i] * (s.size() - i + 1)) % MOD; + } + } + cout<