結果

問題 No.980 Fibonacci Convolution Hard
ユーザー ysystem7
提出日時 2020-03-17 16:58:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 527 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 3,327 ms
コンパイル使用メモリ 210,032 KB
最終ジャッジ日時 2025-01-09 07:32:31
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

ll a[2000005],s[2000005],t[2000005];

int main(){
    ll p;
    cin>>p;
    int Q;
    cin>>Q;
    a[1]=0;
    a[2]=1;
    a[3]=p;
    s[2]=0;
    s[3]=0;
    t[2]=1;
    t[3]=(t[2]+a[3]*a[3]%mod)%mod;
    for(ll i=4;i<=2000000;i++){
        a[i]=((p*a[i-1])%mod+a[i-2])%mod;
        t[i]=(t[i-1]+a[i]*a[i]%mod)%mod;
        if(i%2==0){
            ll k=i/2;
            ll m=(i-2)/2;
            s[i]=((p*s[i-1])%mod+(s[i-2]+a[k]*a[k]%mod+a[k-1]*a[k-1]%mod)%mod)%mod;
        }else{
            ll k=i/2;
            s[i]=((p*((s[i-1]+a[k]*a[k])%mod))%mod+s[i-2]+2*a[k]*a[k-1]%mod)%mod;
        }
    }
    while(Q--){
        int q;
        cin>>q;
        cout<<s[q]<<endl;
    }
}
0