結果
| 問題 |
No.510 二次漸化式
|
| コンテスト | |
| ユーザー |
xxxxxxxxxxxxxxxxxxxx
|
| 提出日時 | 2017-04-29 00:24:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,574 ms / 3,000 ms |
| コード長 | 967 bytes |
| コンパイル時間 | 1,741 ms |
| コンパイル使用メモリ | 170,540 KB |
| 実行使用メモリ | 19,384 KB |
| 最終ジャッジ日時 | 2024-09-13 19:40:10 |
| 合計ジャッジ時間 | 18,321 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const long MOD = 1000000000 + 7;
vector<long>x(1000000);
vector<long>y(1000000);
long calB(int idx)
{
if (idx <= 0) {
return 1;
}
if (y[idx - 1] == 0) {
return 1;
} else {
return (((y[idx - 1] * calB(idx - 1)) % MOD) + 1) % MOD;
}
}
long calA(int idx)
{
if (idx <= 0) {
return 1;
}
if (x[idx - 1] == 0) {
return calA(idx - 1);
} else {
long v = calB(idx - 1);
return (((x[idx - 1] * ((v * v) % MOD) % MOD) + calA(idx - 1)) % MOD);
}
}
int main()
{
int n, q;
cin >> n >> q;
for (int t = 0; t < q; ++t) {
char c;
cin >> c;
switch (c) {
case 'x': {
int idx, val;
cin >> idx >> val;
x[idx] = val;
}
break;
case 'y': {
int idx, val;
cin >> idx >> val;
y[idx] = val;
}
break;
case 'a': {
int idx;
cin >> idx;
cout << calA(idx) << endl;
}
}
}
return 0;
}
xxxxxxxxxxxxxxxxxxxx