結果

問題 No.1172 Add Recursive Sequence
ユーザー beetbeet
提出日時 2020-08-28 13:35:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 4,000 ms
コード長 3,664 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 203,572 KB
実行使用メモリ 12,308 KB
最終ジャッジ日時 2024-04-26 10:36:15
合計ジャッジ時間 3,634 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 60 ms
12,308 KB
testcase_15 AC 38 ms
9,728 KB
testcase_16 AC 220 ms
12,160 KB
testcase_17 AC 191 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/4271"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test

#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif

//BEGIN CUT HERE
template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
//END CUT HERE
#ifndef call_from_test

//INSERT ABOVE HERE
signed ABC127_E(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w,k;
  cin>>h>>w>>k;
  using M = Mint<int>;

  M ans{0};
  for(int d=1;d<h;d++)
    ans+=M(d)*M(h-d)*M(w)*M(w);

  for(int d=1;d<w;d++)
    ans+=M(d)*M(w-d)*M(h)*M(h);

  ans*=M::comb(h*w-2,k-2);
  cout<<ans<<endl;
  return 0;
}
/*
  verified on 2019/06/12
  https://atcoder.jp/contests/abc127/tasks/abc127_e
*/

signed main(){
  //ABC127_E();
  return 0;
}
#endif


#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;

#endif
//BEGIN CUT HERE
// add recursive sequence
template<typename T>
struct RecursiveSequence{
  vector<vector<int>> add,sub;
  RecursiveSequence(int n):add(n),sub(n+1){}

  // add a_0, ..., a_{r-l-1} to [l, r)
  void query(int l,int r){
    add[l].emplace_back(0);
    sub[r].emplace_back(r-l);
  }

  // a_i = \sum_{k} c_k a_{i-k}
  vector<T> build(vector<T> as,vector<T> cs){
    assert(as.size()==cs.size());
    int n=add.size();
    int k=as.size();

    reverse(cs.begin(),cs.end());
    as.resize(n+k);
    for(int i=0;i<n;i++)
      for(int j=0;j<k;j++)
        as[i+k]+=as[i+j]*cs[j];

    vector<T> ss(n+k,T(0));
    for(int i=0;i<n;i++){
      for(int l:add[i])
        for(int j=0;j<k;j++)
          ss[i+j]+=as[l+j];

      for(int l:sub[i])
        for(int j=0;j<k;j++)
          ss[i+j]-=as[l+j];

      for(int j=0;j<k;j++)
        ss[i+k]+=ss[i+j]*cs[j];
    }
    ss.resize(n);
    return ss;
  }
};
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  const char newl = '\n';

  int k,n,m;
  cin>>k>>n>>m;

  using M = Mint<int>;
  vector<M> as(k),cs(k);
  for(int i=0;i<k;i++) cin>>as[i].v;
  for(int i=0;i<k;i++) cin>>cs[i].v;

  RecursiveSequence<M> rs(n);
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    rs.query(l,r);
  }

  auto ss=rs.build(as,cs);
  for(int i=0;i<n;i++) cout<<ss[i]<<newl;
  return 0;
}
0