結果

問題 No.510 二次漸化式
ユーザー ldsyb
提出日時 2017-04-29 00:17:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 779 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 68,148 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 19:37:58
合計ジャッジ時間 26,065 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	using ll = long long;
	constexpr ll mod = 1e9 + 7;
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	ll a[n + 1], b[n + 1], x[n]{}, y[n]{};
	a[0] = b[0] = 1;
	ll puni = 1;
	while(q--){
		char c;
		cin >> c;
		if(c == 'x'){
			ll i, v;
			cin >> i >> v;
			x[i] = v;
			puni = max(1ll, min(puni, i));
		}
		if(c == 'y'){
			ll i, v;
			cin >> i >> v;
			y[i] = v;
			puni = max(1ll, min(puni, i));
		}
		if(c == 'a'){
			int i;
			cin >> i;
			if(puni <= i){
				for(int j = puni; j <= i; j++){
					a[j] = (x[j - 1] * b[j - 1] % mod * b[j - 1] % mod + a[j - 1]) % mod;
					b[j] = (y[j - 1] * b[j - 1] % mod + 1) % mod;
				}
				puni = n + 1;
			}
			cout << a[i] << endl;
		}
	}
}
0