結果

問題 No.2443 特殊線形群の標準表現
ユーザー hiromi_ayasehiromi_ayase
提出日時 2023-08-25 23:19:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 3,000 ms
コード長 3,954 bytes
コンパイル時間 2,671 ms
コンパイル使用メモリ 255,948 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2023-08-25 23:19:11
合計ジャッジ時間 6,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 343 ms
8,740 KB
testcase_16 AC 327 ms
8,832 KB
testcase_17 AC 320 ms
8,776 KB
testcase_18 AC 321 ms
8,728 KB
testcase_19 AC 317 ms
8,724 KB
testcase_20 AC 283 ms
8,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
#include <atcoder/segtree>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

template <typename T, int H, int W>
struct Matrix {
  using Array = array<array<T, W>, H>;
  Array A;

  Matrix() : A() {
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++) (*this)[i][j] = T();
  }

  int height() const { return H; }

  int width() const { return W; }

  inline const array<T, W> &operator[](int k) const { return A[k]; }

  inline array<T, W> &operator[](int k) { return A[k]; }

  static Matrix I() {
    assert(H == W);
    Matrix mat;
    for (int i = 0; i < H; i++) mat[i][i] = 1;
    return (mat);
  }

  Matrix &operator+=(const Matrix &B) {
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++) A[i][j] += B[i][j];
    return (*this);
  }

  Matrix &operator-=(const Matrix &B) {
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++) A[i][j] -= B[i][j];
    return (*this);
  }

  Matrix &operator*=(const Matrix &B) {
    assert(H == W);
    Matrix C;
    for (int i = 0; i < H; i++)
      for (int k = 0; k < H; k++)
        for (int j = 0; j < H; j++) C[i][j] += A[i][k] * B[k][j];
    A.swap(C.A);
    return (*this);
  }

  Matrix &operator^=(long long k) {
    Matrix B = Matrix::I();
    while (k > 0) {
      if (k & 1) B *= *this;
      *this *= *this;
      k >>= 1LL;
    }
    A.swap(B.A);
    return (*this);
  }

  Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }

  Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }

  Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }

  Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }

  bool operator==(const Matrix &B) const {
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++)
        if (A[i][j] != B[i][j]) return false;
    return true;
  }

  bool operator!=(const Matrix &B) const {
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++)
        if (A[i][j] != B[i][j]) return true;
    return false;
  }

  friend ostream &operator<<(ostream &os, const Matrix &p) {
    for (int i = 0; i < H; i++) {
      os << "[";
      for (int j = 0; j < W; j++) {
        os << p[i][j] << (j + 1 == W ? "]\n" : ",");
      }
    }
    return (os);
  }

  T determinant(int n = -1) {
    if (n == -1) n = H;
    Matrix B(*this);
    T ret = 1;
    for (int i = 0; i < n; i++) {
      int idx = -1;
      for (int j = i; j < n; j++) {
        if (B[j][i] != 0) {
          idx = j;
          break;
        }
      }
      if (idx == -1) return 0;
      if (i != idx) {
        ret *= T(-1);
        swap(B[i], B[idx]);
      }
      ret *= B[i][i];
      T inv = T(1) / B[i][i];
      for (int j = 0; j < n; j++) {
        B[i][j] *= inv;
      }
      for (int j = i + 1; j < n; j++) {
        T a = B[j][i];
        if (a == 0) continue;
        for (int k = i; k < n; k++) {
          B[j][k] -= B[i][k] * a;
        }
      }
    }
    return (ret);
  }
};
using mint = atcoder::modint;
using M = Matrix<mint, 2, 2>;

M op(M x, M y) { return y * x; };
M e() {
  M I;
  I[0][0] = I[1][1] = 1;
  return I;
};

int main() {
  FAST_IO

  int n, b, q;
  cin >> n >> b >> q;

  mint::set_mod(b);

  atcoder::segtree<M, op, e> st(n);

  for (int i = 0; i < n; i++) {
    int a1, a2, a3, a4;
    cin >> a1 >> a2 >> a3 >> a4;
    M a;

    a[0][0] = a1;
    a[0][1] = a2;
    a[1][0] = a3;
    a[1][1] = a4;
    st.set(i, a);
  }

  for (int i = 0; i < q; i++) {
    int l, r, x, y;
    cin >> l >> r >> x >> y;
    M v;
    v[0][0] = x;
    v[1][0] = y;
    auto ret = st.prod(l, r) * v;

    cout << ret[0][0].val() << " " << ret[1][0].val() << endl;
  }
}
0