This commit is contained in:
Zengtudor 2024-10-06 17:38:28 +08:00
parent a638d105fb
commit 567c715d0a

View File

@ -1,3 +1,5 @@
#include <algorithm>
#include <initializer_list>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -8,13 +10,20 @@ typedef unsigned long long ull;
template<class T,size_t size> template<class T,size_t size>
struct Array{ struct Array{
constexpr Array(){};
constexpr Array(const std::initializer_list<T> list){
std::copy(list.begin(),list.end(),arr);
}
#ifdef NDEBUG #ifdef NDEBUG
#define NDB_NOEXCEPT noexcept #define NDB_NOEXCEPT noexcept
#define NDB_CONSTEXPR constexpr
#else #else
#define NDB_NOEXCEPT #define NDB_NOEXCEPT
#define NDB_CONSTEXPR
#endif #endif
T& operator[](const size_t n)NDB_NOEXCEPT{ NDB_CONSTEXPR T& operator[](const size_t n)NDB_NOEXCEPT{
#ifndef NDEBUG #ifndef NDEBUG
if(n>=size){ if(n>=size){
std::ostringstream err_oss; std::ostringstream err_oss;
@ -25,8 +34,11 @@ struct Array{
return arr[n]; return arr[n];
} }
struct Iterator{ struct Iterator{
Iterator(const size_t n,const T *p)noexcept:now{n},p{p}{} constexpr Iterator(const size_t n,T *const p)noexcept:now{n},p{p}{}
T& operator*()const NDB_NOEXCEPT{ bool operator!=(const Iterator &that)const noexcept{
return this->now!=that.now;
}
NDB_CONSTEXPR T& operator*()const NDB_NOEXCEPT{
#ifndef NDEBUG #ifndef NDEBUG
if(now>=size){ if(now>=size){
std::ostringstream err_oss; std::ostringstream err_oss;
@ -36,23 +48,41 @@ struct Array{
#endif #endif
return p[now]; return p[now];
} }
Iterator& operator++()noexcept{ constexpr Iterator& operator++()noexcept{
now++; now++;
return *this;
}
constexpr Iterator& operator--()noexcept{
now--;
return *this;
}
constexpr Iterator operator--(int)noexcept{
auto old = *this;
now--;
return old;
} }
private: private:
size_t now; size_t now;
T *p; T *const p;
}; };
Iterator begin()const noexcept{ constexpr Iterator begin()noexcept{
return Iterator(0,*arr); return Iterator(0,arr);
} }
Iterator end()const noexcept{ constexpr Iterator end()noexcept{
return Iterator(size,*arr); return Iterator(size,arr);
} }
private: private:
T arr[size]; T arr[size];
}; };
template<class T,class ...Args>
constexpr static Array<T,sizeof...(Args)> make_array(const Args&...args){
Array<T,sizeof...(Args)> arr;
size_t index {0};
((arr[index++]=args),...);
return arr;
}
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 unused_left_num, ans; static size_t unused_left_num, ans;
@ -61,7 +91,6 @@ static Array<ull,MAX_N> stk;
int main(){ int main(){
cin>>s; cin>>s;
for(size_t i {1};i<=s.size();i++){ for(size_t i {1};i<=s.size();i++){
if(s[i-1]=='('){ if(s[i-1]=='('){
stk[unused_left_num++]=i; stk[unused_left_num++]=i;