結果

問題 No.2443 特殊線形群の標準表現
ユーザー SSRSSSRS
提出日時 2023-08-25 21:35:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 593 ms / 3,000 ms
コード長 1,645 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 214,212 KB
実行使用メモリ 32,904 KB
最終ジャッジ日時 2023-08-25 21:35:29
合計ジャッジ時間 7,731 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 54 ms
5,904 KB
testcase_15 AC 593 ms
32,676 KB
testcase_16 AC 554 ms
32,888 KB
testcase_17 AC 561 ms
32,900 KB
testcase_18 AC 578 ms
32,624 KB
testcase_19 AC 564 ms
32,904 KB
testcase_20 AC 520 ms
32,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int mod(int a, int b){
  a %= b;
  if (a < 0){
    a += b;
  }
  return a;
}
int main(){
  int N, B, Q;
  cin >> N >> B >> Q;
  vector<vector<vector<int>>> A(N, vector<vector<int>>(2, vector<int>(2)));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 2; j++){
      for (int k = 0; k < 2; k++){
        cin >> A[i][j][k];
        A[i][j][k] = mod(A[i][j][k], B);
      }
    }
  }
  vector<vector<vector<long long>>> S(N + 1, vector<vector<long long>>(2, vector<long long>(2, 0)));
  for (int i = 0; i < 2; i++){
    S[0][i][i] = 1 % B;
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 2; j++){
      for (int k = 0; k < 2; k++){
        for (int l = 0; l < 2; l++){
          S[i + 1][j][l] += A[i][j][k] * S[i][k][l];
          S[i + 1][j][l] %= B;
        }
      }
    }
  }
  for (int i = 0; i < Q; i++){
    int L, R, x, y;
    cin >> L >> R >> x >> y;
    x = mod(x, B);
    y = mod(y, B);
    vector<vector<long long>> M1 = S[R];
    vector<vector<long long>> M2 = S[L];
    swap(M2[0][0], M2[1][1]);
    M2[0][1] = mod(-M2[0][1], B);
    M2[1][0] = mod(-M2[1][0], B);
    vector<vector<long long>> P(2, vector<long long>(2, 0));
    for (int j = 0; j < 2; j++){
      for (int k = 0; k < 2; k++){
        for (int l = 0; l < 2; l++){
          P[j][l] += M1[j][k] * M2[k][l];
          P[j][l] %= B;
        }
      }
    }
    vector<int> xx = {x, y};
    vector<long long> ans(2, 0);
    for (int j = 0; j < 2; j++){
      for (int k = 0; k < 2; k++){
        ans[j] += P[j][k] * xx[k];
        ans[j] %= B;
      }
    }
    cout << ans[0] << ' ' << ans[1] << endl;
  }
}
0