結果
問題 |
No.2102 [Cherry Alpha *] Conditional Reflection
|
ユーザー |
|
提出日時 | 2025-04-14 01:53:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 267 ms / 3,000 ms |
コード長 | 5,531 bytes |
コンパイル時間 | 6,330 ms |
コンパイル使用メモリ | 333,788 KB |
実行使用メモリ | 27,472 KB |
最終ジャッジ日時 | 2025-04-14 01:54:21 |
合計ジャッジ時間 | 22,686 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 70 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; namespace my{ #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define jo(a,b) a##b #define FO_IMPL(n,c) for(ll jo(_i,c)=n;jo(_i,c)-->0;) #define FO(n) FO_IMPL(n,__COUNTER__) #define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a) #define schrodinger(p,c) (p?c:remove_cvref_t<decltype(c)>{}) #define base_operator(op,type) auto operator op(const type&v)const{auto copy=*this;return copy op##=v;} #define single_testcase void solve();}int main(){my::io();my::solve();}namespace my{ void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; using u32=uint32_t; using u64=uint64_t; using u128=__uint128_t; constexpr auto range(ll s,ll b){ll a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} constexpr auto range(ll s,ll a,ll b,ll c=1){return array{a-s,b,(1-s*2)*c};} const string newline{char(10)}; const string space{char(32)}; template<class T>struct unordered_set:std::unordered_set<T>{ unordered_set(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);} unordered_set(const vector<T>&a){fe(a,e)this->emplace(e);} ll size()const{return std::unordered_set<T>::size();} T back()const{assert(size());return*prev(this->end());} }; template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>; template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>; template<class V>constexpr int rank(){if constexpr(vectorial<V>)return rank<typename V::value_type>()+1;else return 0;} template<class T>struct core_t_helper{using core_t=T;}; template<vectorial V>struct core_t_helper<V>{using core_t=typename core_t_helper<typename V::value_type>::core_t;}; template<class T>using core_t=core_t_helper<T>::core_t; template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;} template<class V>ostream&operator<<(ostream&o,const vector<V>&v){ll n=v.size();fo(i,n)o<<v[i]<<schrodinger(i<n-1,vectorial<V>?newline:space);return o;} template<class V>struct vec; template<int rank,class T>struct hvec_helper{using type=vec<typename hvec_helper<rank-1,T>::type>;}; template<class T>struct hvec_helper<0,T>{using type=T;}; template<int rank,class T>using hvec=typename hvec_helper<rank,T>::type; template<class V>struct vec:vector<V>{ static constexpr int R=rank<vec<V>>(); using C=core_t<V>; using vector<V>::vector; vec(const vector<V>&v){vector<V>::operator=(v);} vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);} void resizes(const auto&...a){*this=make(a...);} static auto make(ll n,const auto&...a){if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);else return vec<decltype(make(a...))>(n,make(a...));} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} vec&operator+=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]-=u[i];return v;} vec&operator+=(const C&c){fe(*this,e)e+=c;return*this;} vec&operator*=(const C&c){fe(*this,e)e*=c;return*this;} base_operator(^,vec) base_operator(+,vec) base_operator(-,vec) base_operator(+,C); base_operator(*,C); vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} ll size()const{return vector<V>::size();} inline ll h()const requires(R==2){return size();} }; template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>; vec(ll)->vec<ll>; void lin(auto&...a){(cin>>...>>a);} template<class T=ll>auto sinen(const string&b="a"){string s;lin(s);vec<T>r;fe(s,e)r.eb(b.size()==1?e-b[0]:b.find_first_of(e));return r;} template<class T=ll>auto sinen(ll n,const string&b="a"){vec<vec<T>>r;fo(n)r.eb(sinen<T>(b));return r;} void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<schrodinger(--n>0,space)),...);cout<<newline;} auto Yes(bool p=1){return p?"Yes":"No";} void sayYes(bool p=1){pp(Yes(p));} template<class T>struct rolling_hash{ static const ll K=61; static const u64 M=(1LL<<K)-1; static const u64 base=123456789; u64 add(u64 a,u64 b)const{return(a+=b)<M?a:a-M;} u64 sub(u64 a,u64 b)const{return add(a,M-b);} u64 mul(u128 a,u64 b)const{return a*=b,add(a>>K,a&M);} u32 h(u32 x)const{++x;return x^=x<<13,x^=x>>17,x^=x<<5;} ll n; vec<u64>hash_zeta,pow_base; rolling_hash(const vec<T>&s):n(s.size()),hash_zeta(n+1),pow_base(n+1){ pow_base[0]=1; fo(i,n){ hash_zeta[i+1]=add(mul(hash_zeta[i],base),h(s[i])); pow_base[i+1]=mul(pow_base[i],base); } } u64 hash()const{return hash_zeta.back();} u64 hash(ll l,ll r)const{return sub(hash_zeta[r],mul(hash_zeta[l],pow_base[r-l]));} u64 swap_hash(ll i,ll j)const{ auto hi=hash(i,i+1),hj=hash(j,j+1); auto res=hash(); res=sub(res,mul(hi,pow_base[n-1-i])); res=sub(res,mul(hj,pow_base[n-1-j])); res=add(res,mul(hi,pow_base[n-1-j])); res=add(res,mul(hj,pow_base[n-1-i])); return res; } }; single_testcase void solve(){ LL(N); auto s=sinen<int>(N); unordered_set<u64>st; fe(s,e){ rolling_hash<int>hs(e); int ok=st.contains(hs.hash()); fo(j,e.size()-1)ok|=st.contains(hs.swap_hash(j,j+1)); sayYes(ok); st.emplace(hs.hash()); } }}