update
This commit is contained in:
parent
aad305dd03
commit
a638d105fb
@ -1,26 +1,74 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using std::cin, std::cout, std::string, std::for_each_n;
|
using std::cin, std::cout, std::string;
|
||||||
typedef unsigned long long ull;
|
typedef unsigned long long ull;
|
||||||
|
|
||||||
|
template<class T,size_t size>
|
||||||
|
struct Array{
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define NDB_NOEXCEPT noexcept
|
||||||
|
#else
|
||||||
|
#define NDB_NOEXCEPT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
T& operator[](const size_t n)NDB_NOEXCEPT{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if(n>=size){
|
||||||
|
std::ostringstream err_oss;
|
||||||
|
err_oss<<"\n[array_size]: "<<size<<"\n[Your index]: "<<n<<'\n';
|
||||||
|
throw std::runtime_error(err_oss.str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return arr[n];
|
||||||
|
}
|
||||||
|
struct Iterator{
|
||||||
|
Iterator(const size_t n,const T *p)noexcept:now{n},p{p}{}
|
||||||
|
T& operator*()const NDB_NOEXCEPT{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if(now>=size){
|
||||||
|
std::ostringstream err_oss;
|
||||||
|
err_oss<<"[array_size]: "<<size<<" [Your index]: "<<now<<'\n';
|
||||||
|
throw std::runtime_error(err_oss.str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return p[now];
|
||||||
|
}
|
||||||
|
Iterator& operator++()noexcept{
|
||||||
|
now++;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
size_t now;
|
||||||
|
T *p;
|
||||||
|
};
|
||||||
|
Iterator begin()const noexcept{
|
||||||
|
return Iterator(0,*arr);
|
||||||
|
}
|
||||||
|
Iterator end()const noexcept{
|
||||||
|
return Iterator(size,*arr);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
T arr[size];
|
||||||
|
};
|
||||||
|
|
||||||
static const size_t MOD {998244353}, MAX_N {300000+5};
|
static const size_t MOD {998244353}, MAX_N {300000+5};
|
||||||
static string s;
|
static string s;
|
||||||
static size_t left_dp[MAX_N], last_left[MAX_N], unused_left_num, ans;
|
static size_t unused_left_num, ans;
|
||||||
static ull stk[MAX_N];
|
static Array<size_t,MAX_N> left_dp, last_left;
|
||||||
|
static Array<ull,MAX_N> stk;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
cin>>s;
|
cin>>s;
|
||||||
|
|
||||||
for(size_t i {0};i<s.size();i++){
|
for(size_t i {1};i<=s.size();i++){
|
||||||
if(s[i]=='('){
|
if(s[i-1]=='('){
|
||||||
stk[unused_left_num++]=i;
|
stk[unused_left_num++]=i;
|
||||||
}else if(unused_left_num>0){
|
}else if(unused_left_num>0){
|
||||||
last_left[i] = stk[--unused_left_num];
|
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]) % MOD;
|
||||||
left_dp[i] = (left_dp[last_left[i]-1] + last_left[i]+1) % MOD;
|
ans = (ans + left_dp[i] * (s.size() - i+1)) % MOD ;
|
||||||
ans = (ans + left_dp[i] * (s.size() - i)) % MOD ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout<<ans<<'\n';
|
cout<<ans<<'\n';
|
||||||
|
Loading…
Reference in New Issue
Block a user