結果
問題 | No.1975 Zigzag Sequence |
ユーザー | eQe |
提出日時 | 2025-01-09 16:30:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 6,424 bytes |
コンパイル時間 | 10,170 ms |
コンパイル使用メモリ | 332,936 KB |
実行使用メモリ | 10,360 KB |
最終ジャッジ日時 | 2025-01-09 16:31:06 |
合計ジャッジ時間 | 14,397 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 12 ms
5,248 KB |
testcase_04 | AC | 7 ms
5,248 KB |
testcase_05 | AC | 108 ms
6,200 KB |
testcase_06 | AC | 72 ms
5,808 KB |
testcase_07 | AC | 14 ms
5,248 KB |
testcase_08 | AC | 67 ms
5,248 KB |
testcase_09 | AC | 112 ms
7,148 KB |
testcase_10 | AC | 78 ms
5,708 KB |
testcase_11 | AC | 80 ms
6,004 KB |
testcase_12 | AC | 19 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 73 ms
5,876 KB |
testcase_19 | AC | 75 ms
5,880 KB |
testcase_20 | AC | 82 ms
6,004 KB |
testcase_21 | AC | 85 ms
6,004 KB |
testcase_22 | AC | 94 ms
10,084 KB |
testcase_23 | AC | 94 ms
10,228 KB |
testcase_24 | AC | 103 ms
10,228 KB |
testcase_25 | AC | 104 ms
10,360 KB |
testcase_26 | AC | 113 ms
6,260 KB |
testcase_27 | AC | 171 ms
7,924 KB |
testcase_28 | AC | 99 ms
10,228 KB |
testcase_29 | AC | 99 ms
10,100 KB |
testcase_30 | AC | 101 ms
10,096 KB |
testcase_31 | AC | 97 ms
10,228 KB |
testcase_32 | AC | 76 ms
6,004 KB |
testcase_33 | AC | 76 ms
6,004 KB |
testcase_34 | AC | 117 ms
6,640 KB |
testcase_35 | AC | 110 ms
6,772 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; namespace my{ using ml=atcoder::modint1000000007; auto&operator>>(istream&i,ml&x){int t;i>>t;x=t;return i;} auto&operator<<(ostream&o,const ml&x){return o<<(int)x.val();} #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define VL(n,...) vec<ll>__VA_ARGS__;setsize({n},__VA_ARGS__);lin(__VA_ARGS__) #define FO(n) for(ll ij=n;ij-->0;) #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 fof(s,i,...) for(auto[i,i##stop,i##step]=range(s,__VA_ARGS__);(i##step>0)?(i<i##stop):(i>=i##stop);i+=i##step) #define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a) #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 ull=unsigned long long; using ulll=__uint128_t; using lll=__int128_t; istream&operator>>(istream&i,ulll&x){ull t;i>>t;x=t;return i;} ostream&operator<<(ostream&o,const ulll&x){return(x<10?o:o<<x/10)<<ll(x%10);} istream&operator>>(istream&i,lll&x){ll t;i>>t;x=t;return i;} ostream&operator<<(ostream&o,const lll&x){return o<<string(x<0,'-')<<ulll(x>0?x:-x);} constexpr auto range(bool s,auto...a){array<ll,3>r{0,0,1};ll I=0;((r[I++]=a),...);if(!s&&I==1)swap(r[0],r[1]);r[0]-=s;if(s)r[2]*=-1;return r;} constexpr char newline=10; constexpr char space=32; lll pow(lll x,ll n){assert(n>=0);lll r=1;while(n)n&1?r*=x:r,x*=x,n>>=1;return r;} template<class A,class B>struct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} pair(const std::pair<A,B>&p):a(p.first),b(p.second){} auto operator<=>(const pair&)const=default; pair operator+(const pair&p)const{return{a+p.a,b+p.b};} friend istream&operator>>(istream&i,pair&p){return i>>p.a>>p.b;} friend ostream&operator<<(ostream&o,const pair&p){return o<<p.a<<space<<p.b;} }; template<class F=less<>>auto&sort(auto&a,F f={}){ranges::sort(a,f);return a;} auto&unique(auto&a){sort(a).erase(ranges::unique(a).begin(),a.end());return a;} template<class T,class U>ostream&operator<<(ostream&o,const std::pair<T,U>&p){return o<<p.first<<space<<p.second;} template<class...A>ostream&operator<<(ostream&o,const tuple<A...>&t){apply([&](const auto&...a){ll i=sizeof...(a);(((o<<a<<string(--i>0,space))),...);},t);return o;} template<class V>concept vectorial=is_base_of_v<vector<typename V::value_type>,V>; template<class T>struct vec_attr{using core_type=T;static constexpr int d=0;}; template<vectorial V>struct vec_attr<V>{using core_type=typename vec_attr<typename V::value_type>::core_type;static constexpr int d=vec_attr<typename V::value_type>::d+1;}; template<class T>using core_t=vec_attr<T>::core_type; 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){fe(v,e)o<<e<<string(&e!=&v.back(),vectorial<V>?newline:space);return o;} template<class V>struct vec:vector<V>{ using vector<V>::vector; vec(const vector<V>&v){vector<V>::operator=(v);} template<class...A>requires(sizeof...(A)>=3)vec(A...a){const ll n=sizeof...(a)-1;ll s[n];ll i=0;((i<n?s[i++]=a:0),...);*this=make_vec(s,get<n>(tuple{a...}));} template<class T,ll n,ll i=0>static auto make_vec(const ll(&s)[n],T x){if constexpr(i==n-1)return vec<T>(s[i],x);else{auto X=make_vec<T,n,i+1>(s,x);return vec<decltype(X)>(s[i],X);}} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} vec operator^(const vec&u)const{return vec{*this}^=u;} vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;} vec operator+(const vec&u)const{return vec{*this}+=u;} vec operator-(const vec&u)const{return vec{*this}-=u;} vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;} auto lower_bound(const V&x)const{return std::lower_bound(this->begin(),this->end(),x);} ll arg_lower_bound(const V&x)const{return lower_bound(x)-this->begin();} auto scan(const auto&f)const{pair<core_t<V>,bool>r{};fe(*this,e)if constexpr(!vectorial<V>)r.b?f(r.a,e),r:r={e,1};else if(auto s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;return r;} auto sum()const{return scan([](auto&a,const auto&b){a+=b;}).a;} }; template<ll d,class T>struct dvec_helper{using type=vec<typename dvec_helper<d-1,T>::type>;}; template<class T>struct dvec_helper<0,T>{using type=T;}; template<ll d,class T>using dvec=typename dvec_helper<d,T>::type; template<class...A>requires(sizeof...(A)>=2)vec(A...a)->vec<dvec<sizeof...(a)-2,remove_reference_t<decltype(get<sizeof...(a)-1>(declval<tuple<A...>>()))>>>; vec(ll)->vec<ll>; template<ll n,class...A>void setsize(const ll(&l)[n],A&...a){((a=vec<void*>::make_vec(l,core_t<A>{})),...);} void lin(auto&...a){(cin>>...>>a);} auto zip(auto&...a){auto v=(a^...);unique(v);([&](auto&u){fe(u,e)e=v.arg_lower_bound(e);}(a),...);return v;} template<class T>auto val_groups(const vec<T>&a,ll M){ vec<vec<T>>r(M); fo(i,a.size())r[a[i]].eb(i); return r; } template<class T>struct fenwick_tree{ ll n; vec<T>data; fenwick_tree(ll n):n(n),data(n){} fenwick_tree(const vec<T>&a):n(n),data(n){fo(i,n)add(i,a[i]);} ll size()const{return n;} void add(ll i,T x){ assert(0<=i&&i<n); i++; while(i<=n){ data[i-1]+=x; i+=i&-i; } } T sum(ll l,ll r)const{ assert(0<=l&&l<=r&&r<=n); T res=0; while(r>0)res+=data[r-1],r-=r&-r; while(l>0)res-=data[l-1],l-=l&-l; return res; } T get(ll i)const{assert(0<=i&&i<n);return sum(i,i+1);} friend ostream&operator<<(ostream&o,const fenwick_tree&ft){fo(i,ft.size())o<<ft.get(i)<<string(i!=ft.size()-1,space);return o;} }; template<char c=space>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<newline;} single_testcase void solve(){ LL(N); VL(N,a); ll M=zip(a).size(); auto g=val_groups(a,M); ml ans=0; fo(f,2){ fenwick_tree<ml>ft_left(N),ft_right(N); fof(f,x,M){ fe(g[x],i)ans+=ft_left.sum(0,i)*ft_right.sum(i+1,N); fe(g[x],i){ ft_left.add(i,ml{2}.pow(i)); ft_right.add(i,ml{2}.pow(N-1-i)); } } } pp(ans); }}