結果

問題 No.510 二次漸化式
コンテスト
ユーザー legendcn
提出日時 2025-04-12 00:59:47
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,790 ms / 3,000 ms
コード長 800 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 963 ms
コンパイル使用メモリ 210,908 KB
実行使用メモリ 9,228 KB
最終ジャッジ日時 2026-07-08 20:11:56
合計ジャッジ時間 14,487 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
# define int long long
# define lc u << 1
# define rc u << 1 | 1
# define fi first
# define se second
const int N = 1000005, mod = 1e9 + 7;

int n, q;
int x[N], y[N];
signed main ()
{
	// freopen ("generator.in", "r", stdin); freopen ("generator.out", "w", stdout);
    scanf ("%lld%lld", &n, &q);
    while (q -- )
    {
        char op; int k; scanf (" %c%lld", &op, &k);
		if (op == 'x') scanf ("%lld", &x[k]);
		else if (op == 'y') scanf ("%lld", &y[k]);
		else if (op == 'a')
        {
			int a = 1, b = 1;
            for (int i = 0; i < k; i ++ )
            {
				if (x[i]) a = (a + x[i] * b % mod * b % mod) % mod;
				if (y[i]) b = (b * y[i] + 1) % mod;
				else b = 1;
			}
			printf ("%lld\n", a);
		}
	}
	return 0;
}
0