結果

問題 No.426 往復漸化式
ユーザー ei1333333ei1333333
提出日時 2016-09-22 23:33:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,252 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 160,768 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-04-28 19:58:59
合計ジャッジ時間 25,130 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;
const int mod = 1e9 + 7;

int N, Q;

int64 A[100001][3][3];
int64 B[100001][2][2];
int64 a[100001][3];
int64 b[100001][2];
bool updatable[2];

void nextA(int i)
{
  a[i + 1][0] = A[i][0][0] * a[i][0] + A[i][0][1] * a[i][1] + A[i][0][2] * a[i][2];
  a[i + 1][1] = A[i][1][0] * a[i][0] + A[i][1][1] * a[i][1] + A[i][1][2] * a[i][2];
  a[i + 1][2] = A[i][2][0] * a[i][0] + A[i][2][1] * a[i][1] + A[i][2][2] * a[i][2];
  a[i + 1][0] %= mod;
  a[i + 1][1] %= mod;
  a[i + 1][2] %= mod;
}

void prevB(int i)
{
  b[i - 1][0] = B[i][0][0] * b[i][0] + B[i][0][1] * b[i][1];
  b[i - 1][1] = B[i][1][0] * b[i][0] + B[i][1][1] * b[i][1];
  b[i - 1][0] += (6 * i + 0) * a[i][0] + (6 * i + 1) * a[i][1] + (6 * i + 2) * a[i][2];
  b[i - 1][1] += (6 * i + 3) * a[i][0] + (6 * i + 4) * a[i][1] + (6 * i + 5) * a[i][2];
  b[i - 1][0] %= mod;
  b[i - 1][1] %= mod;
}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  for(int i = 0; i < 3; i++) cin >> a[0][i];
  for(int i = 0; i < 2; i++) cin >> b[N][i];
  for(int i = 0; i <= N; i++) for(int j = 0; j < 3; j++) A[i][j][j] = 1;
  for(int i = 0; i <= N; i++) for(int j = 0; j < 2; j++) B[i][j][j] = 1;
  for(int i = 0; i < N; i++) nextA(i);
  for(int i = N; i > 0; i--) prevB(i);

  cin >> Q;
  while(Q--) {
    string type;
    cin >> type;
    if(type == "a") {
      int idx;
      cin >> idx;
      for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) cin >> A[idx][i][j];
      }
      updatable[0] = true;
    } else if(type == "b") {
      int idx;
      cin >> idx;
      for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) cin >> B[idx][i][j];
      }
      updatable[1] = true;
    } else if(type == "ga") {
      if(updatable[0]) for(int i = 0; i < N; i++) nextA(i);
      updatable[0] = false;

      int idx;
      cin >> idx;
      cout << a[idx][0] << " " << a[idx][1] << " " << a[idx][2] << endl;
    } else {
      if(updatable[0]) for(int i = 0; i < N; i++) nextA(i);
      if(updatable[0] | updatable[1]) for(int i = N; i > 0; i--) prevB(i);
      updatable[0] = updatable[1] = false;

      int idx;
      cin >> idx;
      cout << b[idx][0] << " " << b[idx][1] << endl;
    }
  }
}
0