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