結果

問題 No.510 二次漸化式
ユーザー shimasuzu@live.jpshimasuzu@live.jp
提出日時 2017-04-28 22:58:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,293 ms / 3,000 ms
コード長 767 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 25,872 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-10-11 19:37:01
合計ジャッジ時間 24,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 25 ms
4,352 KB
testcase_03 AC 25 ms
4,352 KB
testcase_04 AC 23 ms
4,352 KB
testcase_05 AC 23 ms
4,348 KB
testcase_06 AC 169 ms
4,348 KB
testcase_07 AC 165 ms
4,348 KB
testcase_08 AC 180 ms
4,352 KB
testcase_09 AC 179 ms
4,348 KB
testcase_10 AC 7 ms
4,352 KB
testcase_11 AC 7 ms
4,352 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 8 ms
4,352 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 7 ms
4,352 KB
testcase_16 AC 886 ms
6,108 KB
testcase_17 AC 786 ms
6,156 KB
testcase_18 AC 790 ms
6,092 KB
testcase_19 AC 789 ms
6,168 KB
testcase_20 AC 871 ms
6,160 KB
testcase_21 AC 857 ms
6,176 KB
testcase_22 AC 876 ms
6,160 KB
testcase_23 AC 1,755 ms
6,148 KB
testcase_24 AC 1,755 ms
6,164 KB
testcase_25 AC 1,731 ms
6,072 KB
testcase_26 AC 1,730 ms
6,140 KB
testcase_27 AC 1,714 ms
6,072 KB
testcase_28 AC 1,572 ms
6,092 KB
testcase_29 AC 1,574 ms
6,140 KB
testcase_30 AC 1,552 ms
6,216 KB
testcase_31 AC 9 ms
5,312 KB
testcase_32 AC 9 ms
5,368 KB
testcase_33 AC 10 ms
6,092 KB
testcase_34 AC 2,293 ms
4,616 KB
testcase_35 AC 10 ms
4,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>


typedef long long ll;


ll a[100000+1], b[100000+1], x[100000+1], y[100000+1];
int last_update;


ll m(ll v)
{
	return v%1000000007;
}


void solve(int i)
{
	int j;

	for(j=last_update;j<i;j++)
	{
		a[j+1]=m(m(x[j]*b[j])*b[j]+a[j]);
		b[j+1]=m(y[j]*b[j]+1);
	}
	last_update=i;
	printf("%lld\n", a[i]);
}


void min_u(int &min, int v)
{
	if(min>v) min=v;
}


int main(void)
{
	char oneline[100], t;
	int i, j, v, n, q;

	scanf("%d%d\n", &n, &q);
	last_update=0;
	for(j=0;j<q;j++)
	{
		a[0]=b[0]=1;

		fgets(oneline, sizeof(oneline), stdin);
		sscanf(oneline, "%c%d%d", &t, &i, &v);
		if(t=='x')
		{
			x[i]=v;
			min_u(last_update, i);
		}
		if(t=='y')
		{
			y[i]=v;
			min_u(last_update, i);
		}
		if(t=='a')
		{
			solve(i);
		}
	}

	return 0;
}
0