結果

問題 No.510 二次漸化式
ユーザー Ut.kUt.k
提出日時 2017-04-29 00:01:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,601 ms / 3,000 ms
コード長 795 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 61,368 KB
実行使用メモリ 4,436 KB
最終ジャッジ日時 2023-10-11 19:54:26
合計ジャッジ時間 20,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 884 ms
4,348 KB
testcase_03 AC 1,451 ms
4,348 KB
testcase_04 AC 1,601 ms
4,348 KB
testcase_05 AC 1,193 ms
4,348 KB
testcase_06 AC 376 ms
4,352 KB
testcase_07 AC 370 ms
4,348 KB
testcase_08 AC 363 ms
4,352 KB
testcase_09 AC 367 ms
4,352 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 24 ms
4,348 KB
testcase_12 AC 24 ms
4,348 KB
testcase_13 AC 23 ms
4,348 KB
testcase_14 AC 24 ms
4,352 KB
testcase_15 AC 23 ms
4,352 KB
testcase_16 AC 292 ms
4,348 KB
testcase_17 AC 285 ms
4,352 KB
testcase_18 AC 286 ms
4,348 KB
testcase_19 AC 282 ms
4,352 KB
testcase_20 AC 285 ms
4,352 KB
testcase_21 AC 282 ms
4,348 KB
testcase_22 AC 281 ms
4,352 KB
testcase_23 AC 748 ms
4,352 KB
testcase_24 AC 748 ms
4,352 KB
testcase_25 AC 734 ms
4,352 KB
testcase_26 AC 729 ms
4,356 KB
testcase_27 AC 726 ms
4,352 KB
testcase_28 AC 735 ms
4,348 KB
testcase_29 AC 736 ms
4,348 KB
testcase_30 AC 739 ms
4,348 KB
testcase_31 AC 15 ms
4,436 KB
testcase_32 AC 14 ms
4,348 KB
testcase_33 AC 14 ms
4,352 KB
testcase_34 AC 788 ms
4,348 KB
testcase_35 AC 1,554 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

vector<int> x;
vector<int> y;

long mod(long l) {
  return l % 1000000007;
}

long b(int i) {
  if (i == 0 || y[i - 1] == 0) {
    return 1;
  }
  return mod(mod(y[i - 1]) * b(i - 1) + 1);
}

long a(int i) {
  if (i == 0) {
    return 1;
  }
  if (x[i - 1] == 0) {
    return a(i - 1);
  }
  long bb = mod(b(i - 1));
  return mod(mod(x[i - 1]) * mod(bb * bb) + a(i - 1));
}

int main() {
  int n, q;
  cin >> n >> q;
  x.resize(n);
  fill(x.begin(), x.end(), 0);
  y.resize(n);
  fill(y.begin(), y.end(), 0);

  for (int i = 0; i < q; i++) {
    char c;
    int j;
    cin >> c >> j;
    if (c == 'x') {
      cin >> x[j];
    } else if (c == 'y') {
      cin >> y[j];
    } else {
      cout << a(j) << endl;
    }
  }

  return 0;
}
0