結果

問題 No.1172 Add Recursive Sequence
ユーザー auauaauaua
提出日時 2020-08-16 22:22:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 411 ms / 4,000 ms
コード長 1,876 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 175,524 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-19 18:34:10
合計ジャッジ時間 4,299 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,376 KB
testcase_01 AC 11 ms
5,760 KB
testcase_02 AC 7 ms
5,632 KB
testcase_03 AC 6 ms
5,504 KB
testcase_04 AC 7 ms
5,632 KB
testcase_05 AC 7 ms
5,504 KB
testcase_06 AC 16 ms
5,760 KB
testcase_07 AC 9 ms
5,632 KB
testcase_08 AC 15 ms
5,504 KB
testcase_09 AC 17 ms
5,760 KB
testcase_10 AC 29 ms
5,760 KB
testcase_11 AC 27 ms
5,888 KB
testcase_12 AC 30 ms
6,016 KB
testcase_13 AC 30 ms
6,016 KB
testcase_14 AC 104 ms
7,936 KB
testcase_15 AC 92 ms
8,064 KB
testcase_16 AC 411 ms
7,936 KB
testcase_17 AC 401 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll k,n,m;cin>>k>>n>>m;
    vector<ll>a(100210);
    vector<ll>c(k);
    rep(i,k)cin>>a[i];
    rep(i,k)cin>>c[i];
    //aの生成
    REP(i,k,100210){
        ll res=0;
        rep(j,k){
            res=(res+a[i-j-1]*c[j]%inf)%inf;
        }
        a[i]=res;
    }
    //L以上に全て操作行ってから、R以上に全て操作をおこなったものを引く
    vector<ll>L(m);
    vector<pll>R(m);
    rep(i,m){
        cin>>L[i]>>R[i].first;
        R[i].second=R[i].first-L[i];
    }
    vector<ll>x(100210);
    sort(all(L));
    ll i=0;
    REP(j,k,100210){
        while(i<m&&j>=L[i]+k){
            rep(l,k){
                x[L[i]+l]=(x[L[i]+l]+a[l])%inf;
            }
            i++;
        }
        ll res=0;
        rep(l,k){
            res=(res+c[l]*x[j-l-1]%inf)%inf;
        }
        x[j]=(x[j]+res)%inf;
    }
    //引く方
    i=0;
    vector<ll>y(100210);
    sort(all(R));
    REP(j,k,100210){
        while(i<m&&j>=R[i].first+k){
            //cout<<R[i].first<<' '<<j<<endl;
            rep(l,k){
                y[R[i].first+l]=(y[R[i].first+l]+a[R[i].second+l])%inf;
            }
            i++;
        }
        ll res=0;
        rep(l,k){
            res=(res+c[l]*y[j-l-1]%inf)%inf;
        }
        y[j]=(y[j]+res)%inf;
    }
    rep(i,n){
        ll ans=(x[i]-y[i])%inf;
        if(ans<0)ans+=inf;
        cout<<ans<<endl;
    }
}
0