結果

問題 No.510 二次漸化式
ユーザー gigimegigime
提出日時 2017-04-28 23:44:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 2,885 ms
コンパイル使用メモリ 164,112 KB
実行使用メモリ 5,964 KB
最終ジャッジ日時 2023-10-11 19:50:42
合計ジャッジ時間 4,774 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 18 ms
4,352 KB
testcase_13 AC 18 ms
4,352 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 18 ms
4,352 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 75 ms
5,156 KB
testcase_33 WA -
testcase_34 AC 59 ms
4,348 KB
testcase_35 AC 70 ms
4,352 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 = 300;
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 / BUCKET * BUCKET;i < (idx / BUCKET + 1) * BUCKET && i < N;i++){
		B [i + 1] = (B [i] * Y [i] + 1) % MOD;
	}
	add [idx / BUCKET] = 0;
	ll sum = 0;
	for(ll i = idx / BUCKET * BUCKET;i < (idx + 1) / BUCKET * BUCKET && i < N;i++){
		(sum += X [i] * (B [i] * B [i] % MOD)) %= MOD;
		(add [idx / BUCKET] += sum) %= 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