#define _USE_MATH_DEFINES #include #include using namespace std; /* #include using namespace atcoder; */ /* #include #include using bll = boost::multiprecision::cpp_int; using bdouble = boost::multiprecision::number>; using namespace boost::multiprecision; */ #if defined(LOCAL_TEST) || defined(LOCAL_DEV) #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line #define _GNU_SOURCE 1 #include #endif #ifdef LOCAL_TEST namespace std { template class dvector : public std::vector { public: using std::vector::vector; template , std::nullptr_t> = nullptr> std::vector::reference operator[](std::size_t n) { if (this->size() <= n) { std::cerr << boost::stacktrace::stacktrace() << '\n' << "vector::_M_range_check: __n (which is " << n << ") >= this->size() (which is " << this->size() << ")" << '\n'; } return this->at(n); } template , std::nullptr_t> = nullptr> const T_ operator[](std::size_t n) const { if (this->size() <= n) { std::cerr << boost::stacktrace::stacktrace() << '\n' << "vector::_M_range_check: __n (which is " << n << ") >= this->size() (which is " << this->size() << ")" << '\n'; } return this->at(n); } template , std::nullptr_t> = nullptr> T_& operator[](std::size_t n) { if (this->size() <= n) { std::cerr << boost::stacktrace::stacktrace() << '\n' << "vector::_M_range_check: __n (which is " << n << ") >= this->size() (which is " << this->size() << ")" << '\n'; } return this->at(n); } template , std::nullptr_t> = nullptr> const T_& operator[](std::size_t n) const { if (this->size() <= n) { std::cerr << boost::stacktrace::stacktrace() << '\n' << "vector::_M_range_check: __n (which is " << n << ") >= this->size() (which is " << this->size() << ")" << '\n'; } return this->at(n); } }; template , typename Allocator = std::allocator> class dmultiset : public std::multiset { public: using std::multiset::multiset; const typename std::multiset::iterator erase(const typename std::multiset::iterator it) { return std::multiset::erase(it); } std::size_t erase([[maybe_unused]] const T& x) { std::cerr << boost::stacktrace::stacktrace() << '\n'; assert(false); } std::size_t erase_all_elements(const T& x) { return std::multiset::erase(x); } }; } #define vector dvector #define multiset dmultiset class SIGFPE_exception : std::exception {}; class SIGSEGV_exception : std::exception {}; void catch_SIGFPE([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGFPE_exception(); } void catch_SIGSEGV([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGSEGV_exception(); } signed convertedmain(); signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); } #define main() convertedmain() #else #define erase_all_elements erase #endif #ifdef LOCAL_DEV template std::ostream& operator<<(std::ostream& s, const std::pair& p) { return s << "(" << p.first << ", " << p.second << ")"; } template std::ostream& operator<<(std::ostream& s, const std::array& a) { s << "{ "; for (std::size_t i = 0; i < N; ++i){ s << a[i] << "\t"; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, const std::set& se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, const std::multiset& se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, const std::map& m) { s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, const std::deque& v) { for (std::size_t i = 0; i < v.size(); ++i){ s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template std::ostream& operator<<(std::ostream& s, const std::vector& v) { for (std::size_t i = 0; i < v.size(); ++i){ s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template std::ostream& operator<<(std::ostream& s, const std::vector>& vv) { s << "\\\n"; for (std::size_t i = 0; i < vv.size(); ++i){ s << vv[i] << "\n"; } return s; } template , std::nullptr_t> = nullptr> std::ostream& operator<<(std::ostream& s, const T (&v)[N]) { for (std::size_t i = 0; i < N; ++i){ s << v[i]; if (i < N - 1) s << "\t"; } return s; } #if __has_include() template std::ostream& operator<<(std::ostream& s, const __gnu_pbds::tree& se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, const __gnu_pbds::gp_hash_table& m) { s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; } #endif void debug_impl() { std::cerr << '\n'; } template void debug_impl(const Head& head, const Tail&... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); } #define debug(...) do { std::cerr << ":" << __LINE__ << " (" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); } while (false) constexpr inline long long prodlocal([[maybe_unused]] long long prod, [[maybe_unused]] long long local) { return local; } #else #define debug(...) do {} while (false) constexpr inline long long prodlocal([[maybe_unused]] long long prod, [[maybe_unused]] long long local) { return prod; } #endif //#define int long long using ll = long long; //INT_MAX = (1<<31)-1 = 2147483647, INT64_MAX = (1LL<<63)-1 = 9223372036854775807 constexpr ll INF = std::numeric_limits::max() == INT_MAX ? (ll)1e9 + 7 : (ll)1e18; constexpr ll MOD = (ll)1e9 + 7; //primitive root = 5 //constexpr ll MOD = 998244353; //primitive root = 3 constexpr double EPS = 1e-9; constexpr ll dx[4] = {1, 0, -1, 0}; constexpr ll dy[4] = {0, 1, 0, -1}; constexpr ll dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr ll dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1}; #define rep(i, n) for(ll i=0, i##_length=(n); i< i##_length; ++i) #define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i) #define rrep(i, n) for(ll i=(n)-1; i>=0; --i) #define rrepeq(i, n) for(ll i=(n) ; i>=1; --i) #define all(v) std::begin(v), std::end(v) #define rall(v) std::rbegin(v), std::rend(v) void p() { std::cout << '\n'; } template void p(const Head& head, const Tail&... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); } template inline void pv(const std::vector& v) { for(ll i=0, N=v.size(); i inline bool chmax(T& a, T b) { return a < b && (a = b, true); } template inline bool chmin(T& a, T b) { return a > b && (a = b, true); } template inline void uniq(std::vector& v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); } template inline ll sz(const T& v) { return std::size(v); } template std::vector make_vector_impl(std::vector& sizes, typename std::enable_if<(N==1), const T&>::type x) { return std::vector(sizes.front(),x); } template auto make_vector_impl(std::vector& sizes, typename std::enable_if<(N>1), const T&>::type x) { ll size=sizes.back(); sizes.pop_back(); return std::vector(sizes,x))>(size,make_vector_impl(sizes,x)); } template auto make_vector(const ll (&sizes)[N], const T& x=T()) { std::vector s(N); for(std::size_t i=0; i(s,x); } template struct Indexer { struct iterator { ll _pos; typename T::iterator _it; iterator(typename T::iterator it): _pos(0), _it(it) {} std::pair::reference> operator*() const { return {_pos, *_it}; } iterator& operator++() { ++_pos; ++_it; return *this; } iterator operator++(int) { iterator tmp(*this); ++*this; return tmp; } bool operator==(iterator const& it) const { return _it == it._it; } bool operator!=(iterator const& it) const { return !(*this == it); } }; T& _container; Indexer(T& t): _container(t) {} iterator begin() const { return iterator(_container.begin()); } iterator end() const { return iterator(_container.end()); } }; template Indexer indexer(const T& t) { return Indexer(t); } #define repv(i, val, v) for(auto&& [i, val] : indexer(v)) #if __has_include() template , typename std::enable_if_t, std::nullptr_t> = nullptr> struct fmap : public __gnu_pbds::gp_hash_table { using __gnu_pbds::gp_hash_table::gp_hash_table; template fmap(std::initializer_list> il) : __gnu_pbds::gp_hash_table() { for (auto&& x : il) __gnu_pbds::gp_hash_table::insert(std::pair(*x.begin(), *(x.begin() + 1))); } template ll count(const T& x) const { return __gnu_pbds::gp_hash_table::find(x) != __gnu_pbds::gp_hash_table::end(); } }; #else template using fmap = std::map; #endif /*-----8<-----template-----8<-----*/ //[lib]lazy.cpp /* 実装では木を 1-indexed の配列で表現している。 ノード k について, 親ノードは k/2, 子ノードは 2k, 2k+1 である。 LazySegmentTree(n, f, g, h, M1, OM0):= サイズ n の初期化。 f は2つの区間の要素をマージする二項演算, g は要素と作用素をマージする二項演算(第三引数は対応する区間の長さ), h は作用素同士をマージする二項演算, M1 はモノイドの単位元, M1 はモノイドの単位元, OM0 は作用素の単位元である。 set(k,x):= k 番目の要素に x を代入する。 build():= セグメント木を構築する。 query(a,b):= 区間 [a,b) に対して二項演算した結果を返す。 update(a, b, x) := 区間 [a,b) に作用素 x を適用する。 operator[k] := k 番目の要素を返す。 find_first(a, check) := [a,x) が check を満たす最初の要素位置 x を返す。見つからない場合は -1 を返す。 find_last(b, check) := [x,b) が check を満たす最後の要素位置 x を返す。見つからない場合は -1 を返す。 */ template< typename Monoid, typename OperatorMonoid, typename F , typename G , typename H > class LazySegmentTree { public: ll sz, height; vector< Monoid > data; vector< OperatorMonoid > lazy; const F f; const G g; const H h; const Monoid M1; const OperatorMonoid OM0; LazySegmentTree(ll n, const F &f, const G &g, const H &h, const Monoid &M1, const OperatorMonoid &OM0) : f(f), g(g), h(h), M1(M1), OM0(OM0) { sz = 1; height = 0; while(sz < n) sz <<= 1, height++; data.assign(2 * sz, M1); lazy.assign(2 * sz, OM0); } void set(ll k, const Monoid &x) { data[k + sz] = x; } void build() { for(ll k = sz - 1; k > 0; k--) { data[k] = f(data[2 * k + 0], data[2 * k + 1]); } } inline void propagate(ll k) { if(lazy[k] != OM0) { lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]); lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]); data[k] = reflect(k); lazy[k] = OM0; } } inline Monoid reflect(ll k) { return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]); } inline void recalc(ll k) { while(k >>= 1) data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1)); } inline void thrust(ll k) { for(ll i = height; i > 0; i--) propagate(k >> i); } void update(ll a, ll b, const OperatorMonoid &x) { thrust(a += sz); thrust(b += sz - 1); for(ll l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if(l & 1) lazy[l] = h(lazy[l], x), ++l; if(r & 1) --r, lazy[r] = h(lazy[r], x); } recalc(a); recalc(b); } Monoid query(ll a, ll b) { thrust(a += sz); thrust(b += sz - 1); Monoid L = M1, R = M1; for(ll l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if(l & 1) L = f(L, reflect(l++)); if(r & 1) R = f(reflect(--r), R); } return f(L, R); } Monoid operator[](const ll &k) { return query(k, k + 1); } template< typename C > ll find_subtree(ll a, const C &check, Monoid &M, bool type) { while(a < sz) { propagate(a); Monoid nxt = type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type)); if(check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template< typename C > ll find_first(ll a, const C &check) { Monoid L = M1; if(a <= 0) { if(check(f(L, reflect(1)))) return find_subtree(1, check, L, false); return -1; } thrust(a + sz); ll b = sz; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) { Monoid nxt = f(L, reflect(a)); if(check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template< typename C > ll find_last(ll b, const C &check) { Monoid R = M1; if(b >= sz) { if(check(f(reflect(1), R))) return find_subtree(1, check, R, true); return -1; } thrust(b + sz - 1); ll a = sz; for(b += sz; a < b; a >>= 1, b >>= 1) { if(b & 1) { Monoid nxt = f(reflect(--b), R); if(check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } // [L, R)の範囲で関数check を満たす/満たさない境目のindexを返す // auto check = [](Monoid data){ 何かしら }; // 返却値 = 満たさない最初のindex, 返却値-L = 満たす要素数 // L が固定, たぶん R が機能していない template ll partitionpoint(ll L, ll R, const Func &check){ ll x = find_first(L, [&](const Monoid &data){return !check(data);}); return x==-1||x>R ? R : x; } // R が固定, たぶん L が機能していない // 返却値 = 満たさない最初のindex, R-返却値 = 満たさない要素数 template ll partitionpoint_rev(ll L, ll R, const Func &check){ ll x = find_last(R, [&](const Monoid &data){return check(data);}); return x==-1||x std::ostream& operator<<(std::ostream& s, LazySegmentTree seg) { for(ll i=0; i> S; cout << ((S[0] == '4' || S[0] == '5') ? "Yes" : "No") << endl; } signed main() { #ifndef LOCAL_DEV std::cin.tie(nullptr); std::ios::sync_with_stdio(false); #endif //ll Q; cin >> Q; while(Q--)solve(); solve(); return 0; }