diff --git a/src/U206625/U206625_myself.cpp b/src/U206625/U206625_myself.cpp index f9d644b..04d0833 100644 --- a/src/U206625/U206625_myself.cpp +++ b/src/U206625/U206625_myself.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -8,13 +10,20 @@ typedef unsigned long long ull; template struct Array{ + constexpr Array(){}; + constexpr Array(const std::initializer_list 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 +constexpr static Array make_array(const Args&...args){ + Array 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 stk; int main(){ cin>>s; - for(size_t i {1};i<=s.size();i++){ if(s[i-1]=='('){ stk[unused_left_num++]=i;