結果

問題 No.510 二次漸化式
ユーザー myantamyanta
提出日時 2017-04-29 01:21:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,482 ms / 3,000 ms
コード長 815 bytes
コンパイル時間 1,100 ms
コンパイル使用メモリ 26,016 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-10-11 20:09:08
合計ジャッジ時間 18,001 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 22 ms
4,368 KB
testcase_03 AC 22 ms
4,372 KB
testcase_04 AC 19 ms
4,368 KB
testcase_05 AC 19 ms
4,372 KB
testcase_06 AC 123 ms
4,368 KB
testcase_07 AC 121 ms
4,368 KB
testcase_08 AC 152 ms
4,368 KB
testcase_09 AC 152 ms
4,372 KB
testcase_10 AC 7 ms
4,372 KB
testcase_11 AC 7 ms
4,372 KB
testcase_12 AC 8 ms
4,372 KB
testcase_13 AC 7 ms
4,368 KB
testcase_14 AC 7 ms
4,372 KB
testcase_15 AC 7 ms
4,372 KB
testcase_16 AC 753 ms
6,140 KB
testcase_17 AC 570 ms
6,128 KB
testcase_18 AC 581 ms
6,136 KB
testcase_19 AC 576 ms
6,112 KB
testcase_20 AC 717 ms
6,124 KB
testcase_21 AC 723 ms
6,132 KB
testcase_22 AC 738 ms
6,216 KB
testcase_23 AC 1,482 ms
6,136 KB
testcase_24 AC 1,481 ms
6,128 KB
testcase_25 AC 1,455 ms
6,092 KB
testcase_26 AC 1,446 ms
6,136 KB
testcase_27 AC 1,428 ms
6,124 KB
testcase_28 AC 1,155 ms
6,128 KB
testcase_29 AC 1,152 ms
6,132 KB
testcase_30 AC 1,142 ms
6,048 KB
testcase_31 AC 9 ms
5,392 KB
testcase_32 AC 9 ms
5,316 KB
testcase_33 AC 11 ms
6,068 KB
testcase_34 AC 10 ms
4,492 KB
testcase_35 AC 10 ms
4,568 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 min_u(int &m, int v)
{
	if(m>v) m=v;
}


void max_u(int &m, int v)
{
	if(m<v) m=v;
}


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);
	}
	max_u(last_update, i);
	printf("%lld\n", a[i]);
}


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