結果

問題 No.510 二次漸化式
ユーザー gigimegigime
提出日時 2017-04-29 00:19:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,408 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 167,212 KB
実行使用メモリ 8,292 KB
最終ジャッジ日時 2024-09-13 19:38:22
合計ジャッジ時間 5,534 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 90 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 20 ms
6,940 KB
testcase_11 AC 20 ms
6,944 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 19 ms
6,944 KB
testcase_14 AC 20 ms
7,524 KB
testcase_15 AC 20 ms
6,944 KB
testcase_16 AC 53 ms
6,940 KB
testcase_17 AC 52 ms
6,944 KB
testcase_18 AC 53 ms
7,156 KB
testcase_19 AC 52 ms
6,940 KB
testcase_20 AC 53 ms
6,944 KB
testcase_21 AC 53 ms
7,012 KB
testcase_22 AC 52 ms
7,268 KB
testcase_23 AC 100 ms
6,944 KB
testcase_24 AC 102 ms
7,012 KB
testcase_25 WA -
testcase_26 AC 100 ms
7,012 KB
testcase_27 AC 99 ms
7,016 KB
testcase_28 AC 98 ms
8,028 KB
testcase_29 AC 99 ms
8,292 KB
testcase_30 WA -
testcase_31 AC 129 ms
6,944 KB
testcase_32 AC 130 ms
6,944 KB
testcase_33 AC 131 ms
6,944 KB
testcase_34 AC 64 ms
6,940 KB
testcase_35 AC 80 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,Q;
const int BUCKET = 500,SIZE = 491;
ll add [BUCKET];
ll B [BUCKET * SIZE];
ll X [BUCKET * SIZE],Y [BUCKET * SIZE];
const ll MOD = 1e9 + 7;

ll get(ll r)
{
	ll res = 1;
	for(int i = 0;i < BUCKET;i++){
		if(SIZE * (i + 1) <= r){
			(res += add [i]) %= MOD;
			continue;
		}
		for(int j = SIZE * i;j < r;j++){
			(res += X [j] * (B [j] * B [j] % MOD)) %= MOD;
		}
		break;
	}
	return res;
}

void update(ll idx)
{
	for(ll i = idx / SIZE * SIZE;i < (idx / SIZE + 1) * SIZE && i < N;i++){
		B [i + 1] = (B [i] * Y [i] + 1) % MOD;
	}
	add [idx / SIZE] = 0;
	for(ll i = idx / SIZE * SIZE;i < (idx / SIZE + 1) * SIZE && i < N;i++){
		(add [idx / SIZE] += X [i] * (B [i] * B [i] % MOD)) %= MOD;
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> Q;
	for(ll i = 0;i <= N;i++){
		B [i] = 1;
	}
	FOR(i,0,Q){
		char c;
		ll p,q;
		cin >> c;
		if(c == 'a'){
			cin >> p;
			cout << get(p) << endl;
		}
		else if(c == 'y'){
			cin >> p >> q;
			Y [p] = q;
			update(p);
		}
		else{
			cin >> p >> q;
			X [p] = q;
			update(p);
		}
	}

	return 0;
}
0