結果

問題 No.510 二次漸化式
ユーザー myantamyanta
提出日時 2017-04-29 00:14:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,298 ms / 3,000 ms
コード長 767 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 26,092 KB
実行使用メモリ 6,200 KB
最終ジャッジ日時 2023-10-11 20:43:34
合計ジャッジ時間 24,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 25 ms
4,348 KB
testcase_03 AC 25 ms
4,356 KB
testcase_04 AC 24 ms
4,348 KB
testcase_05 AC 24 ms
4,348 KB
testcase_06 AC 166 ms
4,348 KB
testcase_07 AC 164 ms
4,348 KB
testcase_08 AC 181 ms
4,348 KB
testcase_09 AC 181 ms
4,352 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 7 ms
4,352 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 7 ms
4,352 KB
testcase_16 AC 888 ms
6,088 KB
testcase_17 AC 786 ms
6,136 KB
testcase_18 AC 791 ms
6,148 KB
testcase_19 AC 788 ms
6,136 KB
testcase_20 AC 868 ms
6,100 KB
testcase_21 AC 858 ms
6,120 KB
testcase_22 AC 878 ms
6,144 KB
testcase_23 AC 1,757 ms
6,104 KB
testcase_24 AC 1,759 ms
6,076 KB
testcase_25 AC 1,731 ms
6,092 KB
testcase_26 AC 1,725 ms
6,144 KB
testcase_27 AC 1,715 ms
6,064 KB
testcase_28 AC 1,577 ms
6,200 KB
testcase_29 AC 1,571 ms
6,132 KB
testcase_30 AC 1,555 ms
6,060 KB
testcase_31 AC 9 ms
5,364 KB
testcase_32 AC 9 ms
5,284 KB
testcase_33 AC 9 ms
6,128 KB
testcase_34 AC 2,298 ms
4,580 KB
testcase_35 AC 9 ms
4,552 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