結果

問題 No.1172 Add Recursive Sequence
ユーザー lgswdnlgswdn
提出日時 2023-10-13 15:00:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 366 ms / 4,000 ms
コード長 2,062 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 203,060 KB
実行使用メモリ 14,356 KB
最終ジャッジ日時 2023-10-13 15:00:58
合計ジャッジ時間 4,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,812 KB
testcase_01 AC 4 ms
9,616 KB
testcase_02 AC 4 ms
9,600 KB
testcase_03 AC 4 ms
9,624 KB
testcase_04 AC 4 ms
9,620 KB
testcase_05 AC 4 ms
9,816 KB
testcase_06 AC 4 ms
9,688 KB
testcase_07 AC 4 ms
9,668 KB
testcase_08 AC 4 ms
9,680 KB
testcase_09 AC 4 ms
9,760 KB
testcase_10 AC 12 ms
10,276 KB
testcase_11 AC 11 ms
10,228 KB
testcase_12 AC 9 ms
10,140 KB
testcase_13 AC 9 ms
10,304 KB
testcase_14 AC 73 ms
14,356 KB
testcase_15 AC 36 ms
12,728 KB
testcase_16 AC 366 ms
14,352 KB
testcase_17 AC 362 ms
12,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//vanitas vanitatum et omnia
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}      
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;  
typedef vector<pii> vp; 
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1e5+5,mod=1e9+7;
int k,n,m,a[N],c[N],d[N];
vi p[N],q[N];

signed main() {
  k=read(), n=read(), m=read();
  rep(i,0,k-1) a[i]=read();
  rep(i,1,k) c[i]=read();
  rep(i,k,n) rep(j,1,k) a[i]=(a[i]+a[i-j]*c[j])%mod;
  rep(i,1,m) {
    int l=read()+1, r=read();
    p[l].eb(r), q[r].eb(l);
  }
  rep(i,1,n) {
    if(i>=k) {
      int x=i-k;
      for(int r:p[x]) if(r>=i) {
        rep(p,0,k-1) d[x+p]=(d[x+p]+a[p])%mod;
      }
    }
    int res=0;
    rep(j,0,k-1) if(i-j>0) {
      for(int r:p[i-j]) if(r>=i) res=(res+a[j])%mod;
    }
    rep(j,1,k) if(i-j>=0) d[i]=(d[i]+d[i-j]*c[j])%mod;
    printf("%lld\n",(d[i]+res)%mod);
    for(int l:q[i]) if(i-l>=k) {
      int x=i-l;
      rep(j,0,k-1) d[i-j]=(d[i-j]+mod-a[x-j])%mod;
    }
  }
  return 0;
}
0