結果

問題 No.2394 部分和乗総和
ユーザー eQeeQe
提出日時 2023-07-28 22:59:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 11,471 bytes
コンパイル時間 6,530 ms
コンパイル使用メモリ 334,540 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 20:49:57
合計ジャッジ時間 7,945 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 1 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 1 ms
5,248 KB
testcase_09 AC 1 ms
5,248 KB
testcase_10 AC 1 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 7 ms
5,248 KB
testcase_14 AC 21 ms
5,248 KB
testcase_15 AC 23 ms
5,248 KB
testcase_16 AC 35 ms
5,248 KB
testcase_17 AC 58 ms
5,248 KB
testcase_18 AC 57 ms
5,248 KB
testcase_19 AC 56 ms
5,248 KB
testcase_20 AC 46 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using ml=modint;using m1=std::vector<ml>;
auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;}
auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();}
#define ep emplace
#define eb emplace_back
#define all(a) begin(a),end(a)
#define wh(...) while(__VA_ARGS__)
#define ef(...) else if(__VA_ARGS__)
#define done(...) rr pp(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define ST(...) RD(str,__VA_ARGS__)
#define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__)
#define UL(n,...) u1 __VA_ARGS__;resize({n},__VA_ARGS__);li(__VA_ARGS__)
#define UV(n,...) u1 __VA_ARGS__;resize({n},__VA_ARGS__);vi(__VA_ARGS__)
#define U2(n,m,...) u2 __VA_ARGS__;resize({n,m},__VA_ARGS__);li(__VA_ARGS__)
#define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v)
#define FO(n) for(ll jo(i,15)=n;jo(i,15)-->0;)
#define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i<i##O;i+=i##E)
#define fe(v,...) FE(v,__VA_ARGS__)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define of(i,...) for(au[i##O,i,i##E]=rng(1,__VA_ARGS__);i>=i##O;i-=i##E)
#define debug(...) pp(#__VA_ARGS__,__VA_ARGS__)
#define JO(s,t) s##t
#define jo(s,t) JO(s,t)
#define I(...) template<__VA_ARGS__>
#define J typename
#define O operator
#define au auto
#define cs const
#define ce constexpr
#define ifc if ce
#define rr return
#define uu using
uu std::tuple,std::cin,std::cout,std::deque,std::swap,std::move,std::bitset;
uu std::begin,std::end,std::rbegin,std::minmax,std::gcd,std::lcm,std::is_same_v;
uu std::array,std::true_type,std::false_type;
I(J T)uu ilis=std::initializer_list<T>;
uu vo=void;
vo solve();
uu bo=bool;
uu is=std::istream;uu os=std::ostream;
uu dd=long double;uu ll=long long;
uu ull=unsigned long long;
uu lll=__int128_t;uu ulll=__uint128_t;
uu str=std::string;
I(J T,J U=T)uu map=std::map<T,U>;
I(J T,J U=T)uu umap=std::unordered_map<T,U>;
ll oo=3e18,l998=998244353,l107=1e9+7;
dd ee=1e-12;
str sp=" ",nc="",nl="\n";
struct edg{
  ll t,w;edg(){}
  edg(ll t,ll w=1):t(t),w(w){}
  friend os&O<<(os&o,cs edg&e){rr o<<e.t<<sp<<e.w;}
};
I(J A,J B=A)struct cp{
  A a={};B b={};
  cp(){}
  cp(A a,B b):a(a),b(b){}
  cp(std::pair<A,B>p):a(p.first),b(p.second){}
  bo O<(cs cp&c)cs{rr a!=c.a?a<c.a:b<c.b;}
  bo O>(cs cp&c)cs{rr a!=c.a?a>c.a:b>c.b;}
  friend os&O<<(os&o,cs cp&c){rr o<<c.a<<sp<<c.b;}
};uu cl=cp<ll>;
I(J A,J B=A,J C=A)struct tr{
  A a={};B b={};C c={};
  tr(){}
  tr(A a,B b,C c):a(a),b(b),c(c){}
  bo O<(cs tr&t)cs{rr a!=t.a?a<t.a:b!=t.b?b<t.b:c<t.c;}
  bo O>(cs tr&t)cs{rr a!=t.a?a>t.a:b!=t.b?b>t.b:c>t.c;}
};uu tl=tr<ll>;

I(J T,ll n,J...A)struct TP{uu t=J TP<T,n-1,T,A...>::t;};
I(J T,J...A)struct TP<T,0,A...>{uu t=tuple<A...>;};
I(J T,ll n)uu tp=J TP<T,n>::t;I(ll n)uu tpl=tp<ll,n>;
tpl<3>rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr{a,b-s,c};}
I(J T)ll len(cs T&a){rr a.size();}
I(J T)bo add(T&a,cs T&b){rr a+=b,1;}
I(J T,J U)bo amax(T&a,cs U&b){rr a<b?a=b,1:0;}
I(J T,J U)bo amin(T&a,cs U&b){rr a>b?a=b,1:0;}

I(J A,J B)ce bo same=is_same_v<A,B>;

I(J T)struct is_tp:false_type{};
I(J...A)struct is_tp<tuple<A...>>:true_type{};
I(J T)constexpr bo is_tp_v = is_tp<T>::value;

I(J T)struct is_ar:false_type{};
I(J T,ll n)struct is_ar<array<T,n>>:true_type{};
I(J T)constexpr bo is_ar_v = is_ar<T>::value;

I(J T)struct is_cp:false_type{};
I(J A,J B)struct is_cp<cp<A,B>>:true_type{};
I(J T)constexpr bo is_cp_v = is_cp<T>::value;

I(J T)struct is_tr:false_type{};
I(J A,J B,J C)struct is_tr<tr<A,B,C>>:true_type{};
I(J T)constexpr bo is_tr_v = is_tr<T>::value;

I(J V)struct ve;
I(J V)constexpr bo isv=0;
I(J V)constexpr bo isv<ve<V>> =1;
I(J V)constexpr bo isv<std::vector<V>> =1;

I(J V)au pure_val(V){ifc(isv<V>)rr pure_val(J V::value_type());else rr V();}

I(J V)struct ve:std::vector<V>{
  uu std::vector<V>::vector;
  uu pure_type=decltype(pure_val(J std::vector<V>::value_type()));

  ve(cs std::vector<V>&v={}){fe(v,e)this->eb(e);}

  au&O+=(cs ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;}
  au&O-=(cs ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;}
  I(J U)au&O+=(cs U&x){au&v=*this;fe(v,e)e+=x;rr v;}
  I(J U)au&O-=(cs U&x){au&v=*this;fe(v,e)e-=x;rr v;}
  au O+(cs ve&u){rr ve(*this)+=u;}
  au O-(cs ve&u){rr ve(*this)-=u;}
  I(J U)au O+(cs U&x){rr ve(*this)+=x;}au&O++(){rr*this+=1;}
  I(J U)au O-(cs U&x){rr ve(*this)-=x;}au&O--(){rr*this-=1;}
  au&O^=(cs ve&u){fe(u,e)this->eb(e);rr*this;}
  au O^(cs ve&u){rr ve(*this)^=u;}

  I(J U)au lower_bound(cs U&x){rr std::lower_bound(all(*this),x);}
  I(J U)au upper_bound(cs U&x){rr std::upper_bound(all(*this),x);}
  I(J U)ll arglb(cs U&x){rr lower_bound(x)-begin(*this);}
  I(J U)ll argub(cs U&x){rr upper_bound(x)-begin(*this);}
  ll argmax(){rr std::max_element(all(*this))-begin(*this);}
  ll argmin(){rr std::min_element(all(*this))-begin(*this);}

  vo af(V e={}){this->ep(begin(*this),e);}
  vo df(){this->erase(begin(*this));}

  I(bo f(pure_type&,cs pure_type&),J U)static au scan(cs U&v){
    cp<pure_type,bo>r;
    ifc(!isv<U>)r={v,1};
    else fe(v,x)if(au t=scan<f>(x);t.b)!r.b?r=t,0:f(r.a,t.a);
    rr r;
  }

  au sum(){rr scan<add>(*this).a;}
  au max(){rr scan<amax>(*this).a;}
  au min(){rr scan<amin>(*this).a;}
  vo fill(pure_type x={}){fill(*this,x);}

  au zt(){rr zt(*this);}
  au mb(){rr mb(*this);}

  friend is&O>>(is&i,ve&v){fe(v,e)i>>e;rr i;}
  friend os&O<<(os&o,cs ve<V>&v){
    str s=nl;
    ifc(!isv<V>)s=sp;else ifc(isv<J V::value_type>)s+=nl;
    fe(v,e)o<<e<<(&e!=&rb(v)?s:nc);
    rr o;
  }

  au de(cs str&b="a"){
    ifc(isv<V>){
      ve<str>r;
      fe(*this,e)r.eb(e.de(b));
      rr r;
    }else{
      str r;
      fe(*this,e)r+=len(b)==1?e+b[0]:0<=e&&e<len(b)?b[e]:'|';
      rr r;
    }
  }

private:
  I(J U)static vo fill(ve<U>&v,pure_type x={}){
    fe(v,e)ifc(isv<U>)fill(e,x);else e=x;
  }
  I(J U)static au zt(U v){
    ifc(isv<U>){fe(v,e)e=zt(e);fo(i,len(v)-1)v[i+1]+=v[i];}rr v;
  }
  I(J U)static au mb(U v){
    ifc(isv<U>){fe(v,e)e=mb(e);of(i,len(v)-1)v[i+1]-=v[i];}rr v;
  }
};

I(J T)uu V1=ve<T>;
I(J T)uu V2=V1<V1<T>>;
uu u1=V1<ll>;
uu u2=V2<ll>;

I(J T=ll,ll n,ll i=0)au vec(cs ll(&s)[n],T x={}){
  ifc(n==i+1)rr V1<T>(s[i],x);
  else{au X=vec<T,n,i+1>(s,x);rr V1<decltype(X)>(s[i],X);}
}

I(ll n,J...A)vo resize(cs ll(&l)[n],A&...a){
  ((a=vec(l,pure_val(a))),...);
}

I(J T)struct uset:std::unordered_set<T>{
  uset(cs V1<T>&a={}){fe(a,e)this->ep(e);}
  friend os&O<<(os&o,cs uset&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;}
};

I(J T)struct set:std::set<T>{
  set(cs V1<T>&a={}){fe(a,e)this->ep(e);}
  auto ika_max(cs T&x){
    auto p=this->upper_bound(x);
    rr p!=this->begin()?prev(p):this->end();
  }
  auto ijo_min(cs T&x){
    rr this->lower_bound(x);
  }
  auto between(cs T&l,cs T&r){
    auto p=this->lower_bound(l),q=this->lower_bound(r);
    rr cp{p,q};
  }

  friend os&O<<(os&o,cs set&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;}
};

I(J T)struct mset:std::multiset<T>{
  mset(cs V1<T>&a={}){fe(a,e)this->ep(e);}
  vo uerase(cs T&x){if(this->contains(x))this->erase(this->find(x));}

  auto ika_max(cs T&x){
    auto p=this->upper_bound(x);
    rr p!=this->begin()?prev(p):this->end();
  }
  auto ijo_min(cs T&x){
    rr this->lower_bound(x);
  }

  auto between(cs T&l,cs T&r){
    auto p=this->lower_bound(l),q=this->lower_bound(r);
    rr cp{p,q};
  }

  friend os&O<<(os&o,cs mset&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;}
};
I(J T)uu qmax=std::priority_queue<T>;
I(J T)uu qmin=std::priority_queue<T,ve<T>,std::greater<>>;
uu cls=V1<cl>;uu tls=V1<tl>;uu strs=V1<str>;uu gra=V2<edg>;
u1 dx{-1,0,1,0,-1,1,1,-1},dy{0,-1,0,1,-1,-1,1,1};

ll rnd(ll l,ll r=oo){
  static ull x=76,y=53,z=20,w=41;
  ull t=x^(x<<11);
  x=y,y=z,z=w,w=(w^(w>>19))^(t^(t>>8));
  rr r==oo?w%l:w%(r-l)+l;}
bo odd(ll x){rr x&1;}bo eve(ll x){rr~x&1;}
ll pwm1(ll x){rr 1-2*(x&1);}ll pw2(ll n){rr 1LL<<n;}
I(J T)bo at(T x,ll i){rr x>>i&1;}
ll l2(ulll x){x|=1;ll r=0;wh(x)x>>=1,++r;rr r;}
ll l10(ulll x){x|=1;ll r=0;wh(x)x/=10,++r;rr r;}
I(J T,J U,J V)bo in(T l,U x,V r){rr l<=x&&x<r;}
I(J T)T flo(T x,T y){rr y<0?x=-x,y=-y:x>=0?x/y:(x+1)/y-1;}
I(J T)T cei(T x,T y){rr y<0?x=-x,y=-y:x<=0?x/y:(x-1)/y+1;}
I(J T)T zz(T x){rr x<0?-x:x;}I(J T)T sq(T a){rr a*a;}

I(J T)T&srt(T&a){sort(all(a));rr a;}
I(J T)T&rv(T&a){reverse(all(a));rr a;}
I(J T)T&rsr(T&a){rr rv(srt(a));}
I(J T)T&uq(T&a){srt(a).erase(unique(all(a)),end(a));rr a;}
I(J T)decltype(au)bg(T&a){rr*begin(a);}
I(J T)decltype(au)rb(T&a){rr*rbegin(a);}
I(J T)decltype(au)rb(T&a,ll x){rr*(rbegin(a)+x);}
I(J T)au pof(T&q){au r=bg(q);q.pop_front();rr r;}
I(J T)au pob(T&q){au r=rb(q);q.pop_back();rr r;}
I(J T)au pot(T&a){au r=a.top();a.pop();rr r;}
I(J...A)au max(cs A&...a){rr max(ilis<std::common_type_t<A...>>{a...});}
I(J...A)au min(cs A&...a){rr min(ilis<std::common_type_t<A...>>{a...});}

struct fio{fio(){
  cin.tie(0)->sync_with_stdio(0);
  cout<<std::fixed<<std::setprecision(15);
  std::cerr<<"ok"<<nl;}
}fio;
os&O<<(os&o,cs ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);}
os&O<<(os&o,cs lll&x){rr o<<(x<0?"-":nc)<<ulll(zz(x));}
I(J...A)os&O<<(os&o,cs tuple<A...>&t){
  apply([&](cs au&...a){ll i=0;(((o<<a<<(++i!=sizeof...(a)?sp:nc))),...);},t);
  rr o;
}
I(J T)os&O<<(os&o,cs deque<T>&v){fe(v,e)o<<e<<sp;rr o;}
I(J T,J U)os&O<<(os&o,cs map<T,U>&m){fe(m,e)o<<cp(e)<<nl;rr o;}
I(J...A)vo pp(cs A&...a){
  ll i=0;((cout<<a<<(++i!=sizeof...(a)?sp:nc)),...);cout<<nl;}
I(J V)is&O>>(is&i,V1<V>&v){fe(v,e)i>>e;rr i;}
I(J...A)vo li(A&...a){(cin>>...>>a);}
I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);}
vo Yes(bo y=1){pp(y?"Yes":"No");}vo No(){Yes(0);}

gra tog(cs u2&a){gra g;fe(a,e){g.eb();fe(e,v)rb(g).eb(v);}rr g;}
u2 tou(cs gra&g){u2 a;fe(g,e){a.eb();fe(e,v,w)rb(a).eb(v);}rr a;}
au gi(gra&g,ll m,bo y=0){
  UV(m,a,b,c);--a,--b;
  fo(i,m)g[a[i]].eb(b[i],c[i]),!y?g[b[i]].eb(a[i],c[i]),0:0;rr tuple{a,b,c};}
au gi(u2&g,ll m,bo y=0){
  UV(m,a,b);--a,--b;
  fo(i,m)g[a[i]].eb(b[i]),!y?g[b[i]].eb(a[i]):0;rr tuple{a,b};}
I(J G)au ti(G&g,bo y=0){rr gi(g,len(g)-1,y);}

u1 en(cs str&s,cs str&b="a"){
  u1 r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));rr r;}
u1 sien(cs str&b="a"){ST(s);rr en(s,b);}
u2 en(cs strs&s,cs str&b="a"){u2 r;fe(s,e)r.eb(en(e,b));rr r;}
u2 sien(ll n,cs str&b="a"){u2 r;fo(n)r.eb(sien(b));rr r;}

I(J F)struct rec:F{
  rec(F&&f):F(std::forward<F>(f)){}
  I(J...A)decltype(au)O()(A&&...a)cs{
    rr F::O()(*this,std::forward<A>(a)...);}};
I(J...A)vo dec(A&...a){((--a),...);}
u1 it(ll n,ll x=0){u1 a;fo(i,n)a.eb(i+x);rr a;}
I(J...A)u1 zp(A&...a){
  u1 v=(a^...);uq(v);([&](u1&u){fe(u,e)e=v.arglb(e);}(a),...);rr v;}
I(J F,J...A)u1 vs(F f,A&...a){
  u1 o=it((len(a)&...));sort(all(o),f);
  ([&](au&e){au c=e;fo(i,len(e))e[i]=c[o[i]];}(a),...);rr o;}
I(J F)dd bsd(F f,dd o,dd n){fo(l2(zz(o-n)/ee)+5)(f((o+n)/2)?o:n)=(o+n)/2;rr o;}
I(J F)ll bsl(F f,ll o,ll n){wh(zz(o-n)>1)(f((o+n)/2)?o:n)=(o+n)/2;rr o;}

ll sqr(ll x){ll r=sqrt(zz(x-ee));wh(r+1<=x/(r+1))++r;rr r;}
u1 divs(ll n){u1 r;fo(i,1,sqr(n)+1)if(n%i==0)r.eb(i),r.eb(n/i);rr uq(r);}
cls fact(ll n){
  umap<ll>m;fo(i,2,sqr(n)+1)wh(n%i==0)++m[i],n/=i;if(n>1)++m[n];
  cls r;fe(m,e)r.eb(e);rr srt(r);}
cls rle(cs u1&a){cls r;fe(a,e)len(r)&&e==rb(r).a?++rb(r).b:r.eb(e,1).b;rr r;}
cls rce(u1 a){rr rle(srt(a));}
lll pow(lll x,lll n,ll m=0){
  lll r=1;wh(n)n&1?r*=x:r,x*=x,m?r%=m,x%=m:r,n>>=1;rr r;}
int main(){ll T=1;fo(T)solve();}

vo solve(){
  LL(N,M,B);
  M%=B;
  ml::set_mod(B);
  UL(N,a);

  m1 b(N);
  fo(i,N)b[i]=ml(M).pow(a[i]);

  au dp=vec({N+1},ml());
  dp[0]=1;
  fo(i,N)dp[i+1]=dp[i]*(b[i]+1);
  pp(dp[N]);
}
0