結果

問題 No.1172 Add Recursive Sequence
ユーザー leaf_1415leaf_1415
提出日時 2020-08-14 22:19:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 374 ms / 4,000 ms
コード長 2,029 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 83,280 KB
実行使用メモリ 15,116 KB
最終ジャッジ日時 2024-04-18 22:10:30
合計ジャッジ時間 3,149 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,064 KB
testcase_01 AC 3 ms
8,064 KB
testcase_02 AC 4 ms
8,064 KB
testcase_03 AC 3 ms
8,064 KB
testcase_04 AC 4 ms
8,192 KB
testcase_05 AC 3 ms
8,064 KB
testcase_06 AC 4 ms
8,192 KB
testcase_07 AC 4 ms
8,320 KB
testcase_08 AC 5 ms
8,192 KB
testcase_09 AC 5 ms
8,192 KB
testcase_10 AC 13 ms
9,088 KB
testcase_11 AC 12 ms
8,832 KB
testcase_12 AC 10 ms
8,960 KB
testcase_13 AC 11 ms
9,088 KB
testcase_14 AC 69 ms
15,116 KB
testcase_15 AC 49 ms
13,252 KB
testcase_16 AC 374 ms
15,068 KB
testcase_17 AC 339 ms
13,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint k, n, m;
llint a[100005], c[205];
llint l[100005], r[100005];
llint ans[100005];
vector<llint> vec[100005], vec2[100005];
llint b[205];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> k >> n >> m;
	for(int i = 0; i < k; i++) cin >> a[i];
	for(int i = 1; i <= k; i++) cin >> c[i];
	
	for(int i = k; i <= n; i++){
		llint sum = 0;
		for(int j = 1; j <= k; j++) sum += c[j] * a[i-j] % mod, sum %= mod;
		a[i] = sum;
	}
	
	//for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
	
	for(int i = 1; i <= m; i++){
		cin >> l[i] >> r[i];
		for(int j = l[i]; j < min(l[i]+k, r[i]); j++) ans[j] += a[j-l[i]], ans[j] %= mod;
		if(r[i] - l[i] > k){
			vec[l[i]+k].push_back(i);
			vec2[r[i]].push_back(i);
		}
	}
	
	//for(int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl;
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < k; j++) b[j] += vec[i].size() * a[j] % mod, b[j] %= mod;
		for(int j = 0; j < vec2[i].size(); j++){
			llint R = r[vec2[i][j]], L = l[vec2[i][j]];
			for(int l = 0; l < k; l++) b[l] += mod - a[R-L-k+l], b[l] %= mod;
		}
		llint sum = 0;
		for(int j = 1; j <= k; j++) sum += c[j] * b[k-j] % mod, sum %= mod;
		ans[i] += sum, ans[i] %= mod;
		
		b[k] = sum;
		for(int j = 0; j < k; j++) b[j] = b[j+1];
		
		//for(int j = 0; j < k; j++) cout << b[j] << " "; cout << endl;
	}
	
	for(int i = 0; i < n; i++) cout << ans[i] << "\n";
	flush(cout);
	
	return 0;
}
0