結果

問題 No.1172 Add Recursive Sequence
ユーザー 👑 kmjpkmjp
提出日時 2020-08-14 23:01:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 483 ms / 4,000 ms
コード長 1,527 bytes
コンパイル時間 4,000 ms
コンパイル使用メモリ 203,264 KB
実行使用メモリ 21,148 KB
最終ジャッジ日時 2023-07-31 23:38:25
合計ジャッジ時間 6,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
16,092 KB
testcase_01 AC 5 ms
16,104 KB
testcase_02 AC 6 ms
16,204 KB
testcase_03 AC 6 ms
16,124 KB
testcase_04 AC 6 ms
16,136 KB
testcase_05 AC 5 ms
16,128 KB
testcase_06 AC 9 ms
16,172 KB
testcase_07 AC 8 ms
16,176 KB
testcase_08 AC 9 ms
16,164 KB
testcase_09 AC 8 ms
16,152 KB
testcase_10 AC 35 ms
16,772 KB
testcase_11 AC 36 ms
16,656 KB
testcase_12 AC 32 ms
16,452 KB
testcase_13 AC 31 ms
16,520 KB
testcase_14 AC 207 ms
21,124 KB
testcase_15 AC 167 ms
18,820 KB
testcase_16 AC 483 ms
21,148 KB
testcase_17 AC 441 ms
18,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int K,N,M;
ll A[202020];
ll C[202020];
ll V[202020];

vector<int> add[202020];
vector<int> del[202020];
int L[202020],R[202020];

const ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>N>>M;
	FOR(i,K) cin>>A[i];
	FOR(i,K) cin>>C[i+1];
	for(i=K;i<=N+K+1;i++) {
		for(j=1;j<=K;j++) (A[i]+=C[j]*A[i-j])%=mo;
	}
	
	FOR(i,M) {
		cin>>L[i]>>R[i];
		if(R[i]-L[i]>K) {
			add[L[i]+K].push_back(L[i]);
			del[R[i]].push_back(L[i]);
		}
	}
	
	FOR(i,N+1) {
		FORR(e,add[i]) {
			for(j=1;j<=K;j++) (V[i-j]+=A[K-j])%=mo;
		}
		FORR(e,del[i]) {
			for(j=1;j<=K;j++) (V[i-j]+=mo-A[i-e-j])%=mo;
		}
		if(i>=K) {
			for(j=1;j<=K;j++) (V[i]+=C[j]*V[i-j])%=mo;
		}
	}
	
	FOR(i,M) {
		if(R[i]-L[i]>K) {
			for(j=1;j<=K;j++) (V[R[i]-j]+=A[R[i]-L[i]-j])%=mo;
		}
		else {
			FOR(j,R[i]-L[i]) V[L[i]+j]+=A[j];
		}
	}
	FOR(i,N) cout<<V[i]%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0